#P6271. [湖北省队互测2014] 一个人的数论

[湖北省队互测2014] 一个人的数论

Description

One day, hjy96 came up with a number theory problem:

For a non-negative integer dd and a positive integer nn, define fd(n)f_d(n) as the sum of the dd-th powers of all positive integers less than nn and coprime to nn. For example, f3(10)=13+33+73+93f_3(10) = 1^3 + 3^3 + 7^3 + 9^3.

Given dd and nn, find the value of fd(n)f_d(n). Output the result modulo 109+710^9 + 7.

Of course, hjy96 knows how to do it. But he wants to challenge you...

Input Format

Since nn may be very large, we give the prime factorization of nn.

n=i=1wpiαin=\prod_{i=1}^{w} p_{i}^{\alpha_{i}}

The first line contains a non-negative integer dd and a positive integer ww, separated by spaces.
The next ww lines each contain two positive integers pip_i and αi\alpha_i, separated by spaces. (It is guaranteed that each pip_i is prime and they are pairwise distinct.)

Output Format

One line containing a non-negative integer, representing fd(n)f_d(n) modulo 109+710^9 + 7.

3 2 
2 1 
5 1
1100

Hint

Constraints

The information for each test point is shown in the table below.

ID dd Special Constraints
1 100\leq 100 n105n \leq 10^5
2 =0=0 None
3 =1=1
4 =2=2
5 100\leq 100 w=1w = 1, α1=1 \alpha_1 = 1
6
7 i=1w(αi+1)105 \prod_{i = 1}^w (\alpha_i + 1) \leq 10^5
8 w16w \leq 16
9 None
10

For all test points, it is guaranteed that 1w1031 \leq w \leq 10^3, 2pi1092 \leq p_i \leq 10^9, and 1αi1091 \leq \alpha_i \leq 10^9.

Translated by ChatGPT 5