#P3172. [CQOI2015] 选数

    ID: 2221 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>递推2015重庆各省省选最大公约数,gcd莫比乌斯反演

[CQOI2015] 选数

Description

We know that selecting NN integers from the interval [L,H][L, H] (where LL and HH are integers) yields (HL+1)N(H - L + 1)^N schemes. Little z is curious about the pattern of the greatest common divisor of the numbers selected in this way. He decides to compute the greatest common divisor of the NN integers for every scheme for further study. However, he soon finds the workload too large, so he asks for your help. Your task is simple: Little z will give you an integer KK, and you need to answer how many selection schemes have their greatest common divisor exactly equal to KK.

Since the number of schemes can be large, you only need to output the remainder modulo 109+710^9+7.

Input Format

The input consists of one line containing four space-separated positive integers, in order: N,K,L,HN, K, L, H.

Output Format

Output a single integer, which is the remainder of the required count modulo 109+710^9+7.

2 2 2 4
3

Hint

Sample 1 Explanation.

All possible selection schemes: $(2, 2), (2, 3), (2, 4), (3, 2), (3, 3), (3, 4), (4, 2), (4, 3), (4, 4)$.

Among them, those with greatest common divisor equal to 22 are only 33 groups: (2,2),(2,4),(4,2)(2, 2), (2, 4), (4, 2).

Constraints.

For 100%100\% of the testdata, 1N,K1091\le N, K\le 10^9, 1LH1091\le L\le H\le 10^9, HL105H - L\le 10^5.

Translated by ChatGPT 5