Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define LL long long
  4.  
  5. const LL M = 1e9+7;
  6.  
  7. LL f(LL x, LL bit)
  8. {
  9. x++;
  10. LL period = 1LL<<(bit+1);
  11. LL a = ((period/2)%M)*((x/period)%M);
  12. LL b = x%period - period/2;
  13. if (b>0) a=(a+b)%M;
  14. return a;
  15. }
  16.  
  17. int main()
  18. {
  19. int t;
  20. cin>>t;
  21. while (t--)
  22. {
  23. int l, r;
  24. cin>>l>>r;
  25. if (l>r) swap(l,r);
  26. LL ans = 0;
  27.  
  28. for (int bit = 0; bit<=60; ++bit)
  29. {
  30. LL total = r-l+1;
  31. LL cnt = f(r, bit) - f(l-1, bit);
  32. cnt = (cnt%M + M)%M;
  33. LL rest = total - cnt;
  34. rest = (rest%M + M )%M;
  35.  
  36. total%=M, cnt%=M, rest%=M;
  37. LL inc = (cnt * rest)%M;
  38. LL shift = (1LL<<bit)%M;
  39. inc = (inc*shift)%M;
  40. ans = (ans+inc)%M;
  41. }
  42. cout<<ans<<endl;
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement