#SP0000283. Dãy thừa số nguyên tố nhỏ nhất — nâng cao (Amazing Prime Sequence (hard))
Bài tập thuộc lộ trình
Mục lục đề ⌄
Dãy thừa số nguyên tố nhỏ nhất — nâng cao (Amazing Prime Sequence (hard))
Amazing Prime Sequence (hard)
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
For every integer , let be the smallest prime divisor of . For example, , , and .
Define and for every .
Given a positive integer , output the remainder of modulo , as an integer in .
Input
The only line contains a positive integer .
Output
Print one non-negative integer equal to .
Subtasks
- Subtask 1 (20 points): . Time limit: s.
- Subtask 2 (30 points): . Time limit: s.
- Subtask 3 (50 points): . Time limit: s.
Examples
Example 1
Input
1
Output
0
Explanation
By definition ; there are no terms with .
Example 2
Input
4
Output
7
Explanation
Here , , and . Therefore , , and , unchanged modulo .
Example 3
Input
100
Output
1257
Explanation
Among integers from through , there are whose smallest prime factor is , whose smallest prime factor is , whose smallest prime factor is , and whose smallest prime factor is . The remaining integers are the primes from through , with sum . Therefore:
$$S(100)=50\cdot2+17\cdot3+7\cdot5+4\cdot7+1043=1257.$$As , the answer is 1257.
Example 4
Input
1000000
Output
37568404989
Explanation
For , the exact sum is . This is smaller than , so the printed remainder is the same.
Example 5
Input
1000000000000
Output
7294954823202325427
Explanation
The exact sum before reduction is . Indeed $S(10^{12})=999\cdot2^{64}+7\,294\,954\,823\,202\,325\,427$. Reducing modulo yields 7294954823202325427.