teacher gave him a very difficult task.
Consider two infinite sets of numbers. The first set consists of odd positive numbers (1,3,5,7,…1,3,5,7,…), and the second set consists of even positive numbers (2,4,6,8,…2,4,6,8,…). At the first stage, the teacher writes the first number on the endless blackboard from the first set, in the second stage — the first two numbers from the second set, on the third stage — the next four numbers from the first set, on the fourth — the next eight numbers from the second set and so on. In other words, at each stage, starting from the second, he writes out two times more numbers than at the previous one, and also changes the set from which these numbers are written out to another.
The ten first written numbers: 1,2,4,3,5,7,9,6,8,101,2,4,3,5,7,9,6,8,10. Let's number the numbers written, starting with one.
The task is to find the sum of numbers with numbers from ll to rr for given integers ll and rr. The answer may be big, so you need to find the remainder of the division by 10000000071000000007 (109+7109+7).
Nazar thought about this problem for a long time, but didn't come up with a solution. Help him solve this problem.
Input
The first line contains two integers ll and rr (1≤l≤r≤10181≤l≤r≤1018) — the range in which you need to find the sum.
Output
Print a single integer — the answer modulo 10000000071000000007 (109+7109+7).
Examples
input
1 3
output
7
input
5 14
output
105
input
88005553535 99999999999
output
761141116
Note
In the first example, the answer is the sum of the first three numbers written out (1+2+4=71+2+4=7).
In the second example, the numbers with numbers from 55 to 1414: 5,7,9,6,8,10,12,14,16,185,7,9,6,8,10,12,14,16,18. Their sum is 105105.
题意:给你两个数组,一个只有奇数(1,3,5……),一个只有偶数(2,4,6……),让你合并为一个数组(第一次从奇数组拿一个过来即为1;第二次从偶数组拿两个数进来即为2,4;第三次从奇数组拿四个数进来,即为3,5,7,9,类似后推。)
#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#define ull unsigned long long
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const int N=200005;
const double pi=acos(-1);
const int inf=0x3f3f3f3f;
ll tao(ll x)
{
ll a[2]={0,0};
//a[0]存奇数的个数a[1]存偶数的个数
ll c=1,k=0;
while(x)
{
a[k]+=min(c,x);
x-=min(c,x);
k^=1;
c<<=1;
}//1 3 5 7就是4*4
// 2 4 6 8 就是4*5
ll sum=((a[0]%mod)*(a[0]%mod))%mod;
sum+=((a[1]%mod)*((a[1]+1)%mod))%mod;
return sum%mod;
}
int main()
{
ll l,r;
scanf("%lld%lld",&l,&r);
printf("%lld\n",(tao(r)-tao(l-1)+mod)%mod);
return 0;
}