C. Problem for Nazar(cf)

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;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章