PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000283. Dãy thừa số nguyên tố nhỏ nhất — nâng cao (Amazing Prime Sequence (hard))

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 n≥2n\ge2, let f(n)f(n) be the smallest prime divisor of nn. For example, f(2)=2f(2)=2, f(4)=2f(4)=2, and f(35)=5f(35)=5.

Define S(1)=0S(1)=0 and S(n)=S(n−1)+f(n)S(n)=S(n-1)+f(n) for every n≥2n\ge2.

Given a positive integer NN, output the remainder of S(N)S(N) modulo 2642^{64}, as an integer in [0,264−1][0,2^{64}-1].

Input

The only line contains a positive integer NN.

Output

Print one non-negative integer equal to S(N) mod 264S(N)\bmod2^{64}.

Subtasks

  • Subtask 1 (20 points): 1≤N≤100001\le N\le 10000. Time limit: 55 s.
  • Subtask 2 (30 points): 1≤N≤1000000001\le N\le 100000000. Time limit: 1010 s.
  • Subtask 3 (50 points): 1≤N≤12345678910111\le N\le 1234567891011. Time limit: 2020 s.

Examples

Example 1

Input

1

Output

0

Explanation

By definition S(1)=0S(1)=0; there are no terms f(n)f(n) with n≥2n\ge2.

Example 2

Input

4

Output

7

Explanation

Here f(2)=2f(2)=2, f(3)=3f(3)=3, and f(4)=2f(4)=2. Therefore S(2)=2S(2)=2, S(3)=5S(3)=5, and S(4)=7S(4)=7, unchanged modulo 2642^{64}.

Example 3

Input

100

Output

1257

Explanation

Among integers from 22 through 100100, there are 5050 whose smallest prime factor is 22, 1717 whose smallest prime factor is 33, 77 whose smallest prime factor is 55, and 44 whose smallest prime factor is 77. The remaining integers are the primes from 1111 through 9797, with sum 10431043. Therefore:

$$S(100)=50\cdot2+17\cdot3+7\cdot5+4\cdot7+1043=1257.$$

As 1257<2641257<2^{64}, the answer is 1257.

Example 4

Input

1000000

Output

37568404989

Explanation

For N=106N=10^6, the exact sum is 37 568 404 98937\,568\,404\,989. This is smaller than 2642^{64}, so the printed remainder is the same.

Example 5

Input

1000000000000

Output

7294954823202325427

Explanation

The exact sum before reduction is 18 435 592 284 459 044 389 81118\,435\,592\,284\,459\,044\,389\,811. Indeed $S(10^{12})=999\cdot2^{64}+7\,294\,954\,823\,202\,325\,427$. Reducing modulo 264=18 446 744 073 709 551 6162^{64}=18\,446\,744\,073\,709\,551\,616 yields 7294954823202325427.