#P5493. 质数前缀统计

质数前缀统计

Description

Let S(n)S(n) be the sum of the kk-th powers of all primes not exceeding nn.

Given NN, compute the value of the following expression:

$$\sum_{i=1}^{\lfloor\sqrt{N}\rfloor} i^2 S \!\left( \left\lfloor \frac{N}{i} \right\rfloor \right)$$

All results are taken modulo the given prime pp.

Input Format

One line contains three integers N,k,pN, k, p, separated by spaces.

Output Format

Output one integer on one line, representing the computed result.

10 3 1000000007
1458
100000 0 1000000007
941229402
100000 10 1000000007
446053671

Hint

Sample explanation:

$S \!\left( \left\lfloor \frac{N}{1} \right\rfloor \right)\! = S(10) = 2^3 + 3^3 + 5^3 + 7^3 = 503$.

$S \!\left( \left\lfloor \frac{N}{2} \right\rfloor \right)\! = S(5) = 2^3 + 3^3 + 5^3 = 160$.

$S \!\left( \left\lfloor \frac{N}{3} \right\rfloor \right)\! = S(3) = 2^3 + 3^3 = 35$.

$1^2 S \!\left( \left\lfloor \frac{N}{1} \right\rfloor \right)\! + 2^2 S \!\left( \left\lfloor \frac{N}{2} \right\rfloor \right)\! + 3^2 S \!\left( \left\lfloor \frac{N}{3} \right\rfloor \right)\! = 503 + 640 + 315 = 1458$.

Constraints

Test Point ID NN \le kk \le Time Limit
131\sim 3 10610^6 1010 1s1\texttt s
474\sim 7 4×10104\times {10}^{10} 00 3s3\texttt s
8128\sim 12 1010

For 100%100\% of the testdata, 0k100 \le k \le 10, 1N4×10101 \le N \le 4\times {10}^{10}, 109<p<1.01×109{10}^9 < p < 1.01 \times {10}^9.

Translated by ChatGPT 5