XP Orbs

Time limit: 1.5s Memory limit: 512MB Input: Output:

Task

In Minecraft, for every task completed, the player is rewarded with a certain number of experience points in the form of some green orbs, each orb rewarding the player with different amounts of experience based on its size.

An orb of size ii rewards the player with xpixp_i experience points. Where xpxp is defined as follows:

  • xp1=1xp_1 = 1;
  • xpi=prevprime(2xpi1)xp_i = prev_{prime}(2 \cdot xp_{i-1}), where prevprime(a)prev_{prime}(a) is the largest prime number that is smaller than or equal to aa. For example, prevprime(16)=13prev_{prime}(16) = 13 and prevprime(23)=23prev_{prime}(23) = 23.

For instance, the first 88 sizes of orbs reward the player with: 1,2,3,5,7,13,231, 2, 3, 5, 7, 13, 23 and 4343 experience points, respectively.

Notch, the creator of Minecraft, made it so that any non-negative integer number of experience points can be broken down as a sum of experience rewarded by orbs in the following way (here \oplus represents array concatenation):

  • Let dec(a)dec(a) be an array representing the decomposition of aa experience points as a sum of experience rewarded by orbs;
  • dec(0)=[ ]dec(0) = [\ ] (the empty array)
  • dec(a)=[xpmax]  dec(axpmax)dec(a) = [xp_{max}]\ \oplus\ dec(a - xp_{max}), where xpmaxxp_{max} is the largest element in xpxp such that xpmaxaxp_{max} \leq a. For example, the decomposition of 11 is dec(11)=[7,3,1]dec(11) = [7, 3, 1] and the decomposition of 1515 is dec(15)=[13,2]dec(15) = [13, 2].
    He also defined cnt(a)cnt(a) to be the length of the array dec(a)dec(a), therefore cnt(11)=3,cnt(15)=2cnt(11) = 3, cnt(15) = 2.

Notch wants to know the answer to qq queries of the following form:

  • l,r l, r\ - find the sum lcnt(l)+l+1cnt(l+1)++r1cnt(r1)+rcnt(r)\frac{l}{cnt(l)}+\frac{l+1}{cnt(l+1)}+\dots+\frac{r-1}{cnt(r-1)}+\frac{r}{cnt(r)}

Input data

The first line contains a single integer representing the number of queries qq.
Each of the next qq lines contains a pair of integers. The ithi^{th} of these lines describes the ithi^{th} query: lil_i and rir_i.

Output data

The output contains qq lines. The ithi^{th} of these lines contains a single integer representing the answer to the ithi^{th} query.

Constraints and clarifications

  • 1q51041 \leq q \leq 5 \cdot 10^4
  • 1liri10121 \leq l_i \leq r_i \leq 10^{12}
  • For tests worth 1818 points, 0rili<1000 \leq r_i - l_i < 100
  • For tests worth 6565 more points, 1liri1081 \leq l_i \leq r_i \leq 10^8

Example 1

stdin

2
5 12
1 1000000

stdout

166374097
439931963

Explanation

For the first query in the first example, the answer, starting with ans=0ans = 0, can be computed as follows:

  • dec(5)=[5]ans=ans+51dec(5) = [5] \rightarrow ans = ans + \frac{5}{1}
  • dec(6)=[5,1]ans=ans+62dec(6) = [5, 1] \rightarrow ans = ans + \frac{6}{2}
  • dec(7)=[7]ans=ans+71dec(7) = [7] \rightarrow ans = ans + \frac{7}{1}
  • dec(8)=[7,1]ans=ans+82dec(8) = [7, 1] \rightarrow ans = ans + \frac{8}{2}
  • dec(9)=[7,2]ans=ans+92dec(9) = [7, 2] \rightarrow ans = ans + \frac{9}{2}
  • dec(10)=[7,3]ans=ans+102dec(10) = [7, 3] \rightarrow ans = ans + \frac{10}{2}
  • dec(11)=[7,3,1]ans=ans+113dec(11) = [7, 3, 1] \rightarrow ans = ans + \frac{11}{3}
  • dec(12)=[7,5]ans=ans+122dec(12) = [7, 5] \rightarrow ans = ans + \frac{12}{2}

The total sum is ans=2296ans = \frac{229}{6} and the output is:
229modinv(6) mod 998 244 353=229166 374 059 mod 998 244 353=166 374 097229 \cdot modinv(6)\ mod\ 998\ 244\ 353 = 229 \cdot 166\ 374\ 059\ mod\ 998\ 244\ 353 = 166\ 374\ 097.

Example 2

stdin

5
11 15
5 14
3 10
12 20
7 19

stdout

166374096
166374117
499122210
499122249
665496322

Log in or sign up to be able to send submissions!