#P13561. 「WWOI R1」WsW 的笔

「WWOI R1」WsW 的笔

Background

WsW is planning to give some pens to bln.

Problem Description

WsW has ba+1b-a+1 pens. Each pen has a unique integer label in the range aba\sim b. He decides to give some of the pens to bln and keep the rest for himself.

When all pens satisfy the following conditions, WsW considers the plan an excellent pen-giving plan:

  • If the pen labeled xx is given to bln, then the pen labeled x/kx/k must be kept by WsW.
  • If the pen labeled xx is kept by WsW, then the pen labeled x/kx/k must be given to bln.

Of course, these conditions only apply if WsW has a pen labeled x/kx/k.

WsW believes that if a pen with some label is given away in one plan but kept in another plan, then these two pen-giving plans are different.

Now all pens have been labeled. WsW wants to know how many different excellent pen-giving plans there are in total.

Since the answer may be very large, you only need to output the total number of plans modulo 109+710^9+7.

Input Format

This problem contains multiple test cases.

The first line contains a positive integer TT, which is the number of test cases.

Then follow TT test cases. Each test case is formatted as follows:

The first line contains a positive integer kk.

The second line contains two positive integers a,ba,b, which specify the range of pen labels.

Output Format

For each test case, output one line containing an integer, indicating the number of different excellent pen-giving plans. Output the answer modulo 109+710^9+7.

1
2
2 2
2
1
3
1 4
8
1
114
514 1919810
532406817

Hint

Sample 11 Explanation

Plan Given labels Kept labels
11 22 None
22 None 22

There are 22 different excellent pen-giving plans in total.

Sample 22 Explanation

Plan Given labels Kept labels
11 2,3,42,3,4
22 1,21,2 3,43,4
33 1,41,4 2,32,3
44 1,2,41,2,4 33
55 33 1,2,41,2,4
66 2,32,3 1,41,4
77 3,43,4 1,21,2
88 2,3,42,3,4 11

There are 88 different excellent pen-giving plans in total.

Constraints

This problem uses bundled tests.

For all testdata, it is guaranteed that 1T51\le T\le 5, 1ab10181\le a\le b\le 10^{18}, 2k1052\le k\le10^{5}.

Subtask ID a,ba,b\leq Special Property Score
11 2020 None 1010
22 10310^3
33 10510^5 B 55
44 None 1010
55 7×1067\times10^6 A 55
66 B
77 None 1515
88 101810^{18} A 55
99 B 1010
1010 None 2525
  • Special Property A: a×k>ba\times k>b.
  • Special Property B: k=2k=2.

Translated by ChatGPT 5