CF-2277D1•Codeforces

Number Operating (Easy Version)

binary searchbitmasksbrute forcegreedy

Ariana Grande - stay

This is the easy version of the problem. The difference between the versions is that in this version, the sum of r−l+1r - l + 1 over all test cases does not exceed 2⋅1052 \cdot 10^5.

You have a variable xx, initially equal to 00. In one operation, you can do one of the following:

  • Operation 11: add 2k2^k to xx, where kk is the number of times Operation 11 has been performed in a row immediately before this one (in particular, k=0k = 0 if this is the first operation or the previous operation was Operation 22);
  • Operation 22: subtract 11 from xx (the result may be negative).

For a non-negative integer nn, let f(n)f(n) be the minimum number of operations needed to make xx equal to nn. It can be shown that this is always possible.

You are given two integers ll and rr. Find ∑n=lrf(n)\sum\limits_{n = l}^{r} f(n). Since the answer can be very large, output it modulo 998 244 353998\,244\,353.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The only line of each test case contains two integers ll and rr (0≤l≤r≤10180 \le l \le r \le 10^{18}).

It is guaranteed that the sum of r−l+1r - l + 1 over all test cases does not exceed 2⋅1052 \cdot 10^5.

Output

For each test case, output a single integer — the value of ∑n=lrf(n)\sum\limits_{n = l}^{r} f(n) modulo 998 244 353998\,244\,353.

Note

In the first test case, l=r=4l = r = 4. Initially, x=0x = 0. One optimal sequence of 66 operations is as follows:

  1. Perform Operation 11 with k=0k = 0, so xx becomes 0+20=10 + 2^0 = 1.
  2. Perform Operation 11 with k=1k = 1, so xx becomes 1+21=31 + 2^1 = 3.
  3. Perform Operation 11 with k=2k = 2, so xx becomes 3+22=73 + 2^2 = 7.
  4. Perform Operation 22, so xx becomes 7−1=67 - 1 = 6.
  5. Perform Operation 22, so xx becomes 6−1=56 - 1 = 5.
  6. Perform Operation 22, so xx becomes 5−1=45 - 1 = 4.

It can be shown that x=4x = 4 cannot be reached in 55 or fewer operations. Thus, f(4)=6f(4) = 6, and the answer is 66.

In the second test case, l=1l = 1 and r=3r = 3. We have f(1)=1f(1) = 1, f(2)=3f(2) = 3, and f(3)=2f(3) = 2. Thus, the answer is 1+3+2=61 + 3 + 2 = 6.

In the third test case, l=r=127l = r = 127. We can perform Operation 11 seven times in a row to reach x=27−1=127x = 2^7 - 1 = 127. It can be shown that x=127x = 127 cannot be reached in 66 or fewer operations. Thus, f(127)=7f(127) = 7, and the answer is 77.

Sample 1
Input
5
4 4
1 3
127 127
0 1000
999999999999900001 1000000000000000000
Output
6
6
7
25383
102936941

Discussions & Comments

Share your approach or ask questions about this problem (0)

You must be logged in to comment or start a discussion on this problem.

Log In

No comments yet. Be the first to comment!

Actions

Open on Codeforces

About Platform

CO
Codeforces
External Judge

Problem Discussions

0

Have questions or want to share your solution approach? Join the discussion.

View / write comments