cswork / OAOpen practice workspace

MoveworksOA #3

Sum of Cubes of Beautiful Numbers

HardJudge-ready

Topics (AI-labelled)Bits & MathBinary SearchPrefix & Ranges

A positive integer is a beautiful number if its binary representation without leading zeros contains at least 1 and at most 3 zeros. For each closed interval [L,R], find the sum of the cubes of all beautiful integers in it, modulo 998244353. All queries are independent.

Input

The first line contains Q, followed by Q lines each with two integers L R. Full original ranges: 1≤Q≤200000, 1≤L≤R≤10^18. Leading zeros are not counted.

Output

Output Q integers in input order, one per line, each in 0..998244352. The original text explicitly requires Q results, and the starter's single long return type cannot express multiple queries, so this problem follows the output format in the statement.

Example 1

Input:

2
5 8
10 15

Output:

853
9000

Example 2

Input:

5
1 1
2 2
7 7
8 8
16 16

Output:

0
8
0
512
0

Example 3

Input:

1
1 10

Output:

2654

Example notes

The original first example keeps its input, with the output corrected to 853 and 9000: [5,8] contains 5, 6, 8, and the original explanation missed 6; [10,15] contains 10, 11, 12, 13, 14. The original 153/0 and the explanation's 637/0 both contradict the explicit definition. the single values 1, 2, 7, 8, 16 give 0, 8, 0, 512, 0 respectively; in [1,10], the cubes of 2, 4, 5, 6, 8, 9, 10 sum to 2654.

Editorial

Loading solution…