F - Coincidence Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600600

問題文

整数 L,RL, R が与えられます。整数の組 (x,y)(x, y) (LxyR)(L \leq x \leq y \leq R) であって、yyxx で割った余りが y XOR xy \text{ XOR } x に等しいものの個数を 109+710^9 + 7 で割ったあまりを求めてください。

 XOR \text{ XOR } とは

整数 A,BA, B のビットごとの排他的論理和 a XOR ba \text{ XOR } b は、以下のように定義されます。

  • a XOR ba \text{ XOR } b を二進数表記した際の 2k2^k (k0k \geq 0) の位の数は、A,BA, B を二進数表記した際の 2k2^k の位の数のうち一方のみが 11 であれば 11、そうでなければ 00 である。
例えば、3 XOR 5=63 \text{ XOR } 5 = 6 となります (二進数表記すると: 011 XOR 101=110011 \text{ XOR } 101 = 110)。

制約

  • 1LR10181 \leq L \leq R \leq 10^{18}

入力

入力は以下の形式で標準入力から与えられる。

LL RR

出力

条件を満たす整数の組 (x,y)(x, y) (LxyR)(L \leq x \leq y \leq R) の個数を 109+710^9 + 7 で割ったあまりを出力せよ。


入力例 1Copy

Copy
2 3

出力例 1Copy

Copy
3

条件を満たす組は (2,2),(2,3),(3,3)(2, 2), (2, 3), (3, 3)33 通りです。


入力例 2Copy

Copy
10 100

出力例 2Copy

Copy
604

入力例 3Copy

Copy
1 1000000000000000000

出力例 3Copy

Copy
68038601

個数を 109+710^9 + 7 で割ったあまりを計算することを忘れないでください。

Score : 600600 points

Problem Statement

Given are integers LL and RR. Find the number, modulo 109+710^9 + 7, of pairs of integers (x,y)(x, y) (LxyR)(L \leq x \leq y \leq R) such that the remainder when yy is divided by xx is equal to y XOR xy \text{ XOR } x.

What is  XOR \text{ XOR }?

The XOR of integers AA and BB, A XOR BA \text{ XOR } B, is defined as follows:

  • When A XOR BA \text{ XOR } B is written in base two, the digit in the 2k2^k's place (k0k \geq 0) is 11 if either AA or BB, but not both, has 11 in the 2k2^k's place, and 00 otherwise.
For example, 3 XOR 5=63 \text{ XOR } 5 = 6. (In base two: 011 XOR 101=110011 \text{ XOR } 101 = 110.)

Constraints

  • 1LR10181 \leq L \leq R \leq 10^{18}

Input

Input is given from Standard Input in the following format:

LL RR

Output

Print the number of pairs of integers (x,y)(x, y) (LxyR)(L \leq x \leq y \leq R) satisfying the condition, modulo 109+710^9 + 7.


Sample Input 1Copy

Copy
2 3

Sample Output 1Copy

Copy
3

Three pairs satisfy the condition: (2,2)(2, 2), (2,3)(2, 3), and (3,3)(3, 3).


Sample Input 2Copy

Copy
10 100

Sample Output 2Copy

Copy
604

Sample Input 3Copy

Copy
1 1000000000000000000

Sample Output 3Copy

Copy
68038601

Be sure to compute the number modulo 109+710^9 + 7.



2025-03-28 (Fri)
13:44:12 +00:00