Problem:
Score : 600 points

Problem Statement

Given are integers L and R. Find the number, modulo 10^9 + 7, of pairs of integers (x, y) (L \leq x \leq y \leq R) such that the remainder when y is divided by x is equal to y \mbox{ XOR } x.

What is \mbox{ XOR }?

The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:

When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.

For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Constraints

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

Input

Input is given from Standard Input in the following format:

L R

Output

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

Sample Input 1

2 3

Sample Output 1

3

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

Sample Input 2

10 100

Sample Output 2

604

Sample Input 3

1 1000000000000000000

Sample Output 3

68038601

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

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int mod=1e9+7;
 
ll L,R;
 
ll f[64][2][2][2][2];
int l[100],r[100];
 
ll dfs(int x,int fl,int fr,int s,int ht)
{
	if(x<0)return 1;
	// x：第x位 （二进制转十进制下权值是1的为第0位）
	// fl： y之前是否有填过小于 R的某一位的数字   例如：R:11000 y:10??? fl即为1 表示后面数字可以往大了填 
	// fr： x之前是否有填过大于 L的某一位的数字   类似fl
	// s： 之前x是否有某一位 < y的某一位 如果有，后面的位数就没有相对大小限制了 (确保 x<=y)
	//ht：确保 x，y 最高位一样都为1  （满足推导的要求） 
	ll &ans=f[x][fl][fr][s][ht];
	if(ans)return ans;
	
	for(int i=0;i<2;i++)//y
	{
		for(int j=0;j<2;j++)//x
		{
			int tl=fl,tr=fr,ts=s,tt=ht;
			if(!tt&&i)if(i!=j)continue;
			if((j&i)!=j)continue;
			if(!tl&&j<l[x])continue;
			if(!tr&&i>r[x])continue;
			if(!ts&&j>i)continue;
			if(j>l[x])tl=1;if(i<r[x])tr=1;if(j<i)ts=1;if(j)tt=1;
			ans+=dfs(x-1,tl,tr,ts,tt);
		}
	}
	ans%=mod;
	return ans;
}
 
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	cin>>L>>R;
	for(int i=63;i>=0;i--)
	{
		l[i]=(bool)((1ll<<i)&L);r[i]=(bool((1ll<<i)&R));
	}
	
	cout<<dfs(63,0,0,0,0);
	
	return 0;
}