#P3362. Cool loves shaxian

Cool loves shaxian

Description

Shaxian is famous for being lavish when paying endorsement (dàiyán) fees. When this Shaxian pays endorsement fees, it uses an exponent dd. It will pay fees for nn rounds. In the ii-th round, it pays f(i)=kikd(in)f(i) = \sum_{k|i} k^d (i \leq n) money.

Now there are QQ queries. Each query asks: if Cool participates from round LiL_i to round RiR_i, how much money will he receive? (It is guaranteed that 1LiRin1 \leq L_i \leq R_i \leq n.)

Since the Shaxian Snacks on South Street is insanely rich, we need to compute the answer modulo 109+710^ 9 + 7.

Input Format

The input contains multiple lines.

The first line contains three integers, n,d,Qn, d, Q (n107n\leq 10^7, d1018d\leq 10^{18}, Q5×104Q\leq 5\times 10^4).

The next QQ lines each contain two integers Li,RiL_i, R_i.

Output Format

The output contains QQ lines.

Each line contains one integer, the amount of endorsement fee Cool receives.

10 2 2
4 5
8 10
47
306
1000 0 1
720 720
30

Hint

Sample 1:

f(4)=12+22+42=21f(4) = 1^2 + 2^2 + 4^2 = 21.

f(5)=12+52=26f(5) =1^2+5^2= 26.

f(8)+f(9)+f(10)=85+91+130=306f(8) + f(9) + f (10) = 85 + 91 + 130= 306.

Sample 2:

This is essentially the number of divisors of the number 720720~.

Translated by ChatGPT 5