Advertisement
Diogo03

Untitled

Oct 31st, 2023 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define pb push_back
  4. using vi = vector<int>;
  5. using vc = vector<char>;
  6. using vs = vector<string>;
  7. using ll = long long;
  8. using vll = vector<ll>;
  9. using vvi = vector<vector<int>>;
  10. using vii = vector<pair<int,int>>;
  11. using namespace std;
  12. const ll mod = 1e9+7;
  13.  
  14. ll g(ll s) {
  15.     ll sum = 0;
  16.     if(s < 4) return 0;
  17.     for(ll i = 2; i < 61; i++) {
  18.         if(s < (1ll << i)) return sum;
  19.         ll p = i, l = (1ll << i), r = (1ll << (i + 1)) - 1, cnt = 1;
  20.         if(r > s) r = s;
  21.         while(1) {
  22.             if(l > r) break;
  23.             if(p > l / i) {
  24.                 if(p > r / i) {
  25.                     sum += (r - l + 1) % mod * cnt % mod, sum %= mod;
  26.                     break;
  27.                 }
  28.                 else sum += (p * i - l) % mod * cnt % mod, sum %= mod;
  29.                 l = p * i;
  30.             }
  31.             p *= i;
  32.             ++cnt;
  33.         }
  34.     }
  35.     return sum;
  36. }
  37. void solve() {
  38.     ll l,r;
  39.     cin >> l >> r;
  40.     ll ans = g(r) - g(l - 1);
  41.     ans = (ans % mod + mod) % mod;
  42.     cout<< (ll)ans << endl;
  43. }
  44. int main() {
  45.     ios::sync_with_stdio(false);
  46.     cin.tie(NULL);
  47.     int t;
  48.     cin >> t;
  49.     while(t--)
  50.     solve();
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement