Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define LL long long
- const LL M = 1e9+7;
- LL f(LL x, LL bit)
- {
- x++;
- LL period = 1LL<<(bit+1);
- LL a = ((period/2)%M)*((x/period)%M);
- LL b = x%period - period/2;
- if (b>0) a=(a+b)%M;
- return a;
- }
- int main()
- {
- int t;
- cin>>t;
- while (t--)
- {
- int l, r;
- cin>>l>>r;
- if (l>r) swap(l,r);
- LL ans = 0;
- for (int bit = 0; bit<=60; ++bit)
- {
- LL total = r-l+1;
- LL cnt = f(r, bit) - f(l-1, bit);
- cnt = (cnt%M + M)%M;
- LL rest = total - cnt;
- rest = (rest%M + M )%M;
- total%=M, cnt%=M, rest%=M;
- LL inc = (cnt * rest)%M;
- LL shift = (1LL<<bit)%M;
- inc = (inc*shift)%M;
- ans = (ans+inc)%M;
- }
- cout<<ans<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement