Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define pb push_back
- using vi = vector<int>;
- using vc = vector<char>;
- using vs = vector<string>;
- using ll = long long;
- using vll = vector<ll>;
- using vvi = vector<vector<int>>;
- using vii = vector<pair<int,int>>;
- using namespace std;
- const ll mod = 1e9+7;
- ll g(ll s) {
- ll sum = 0;
- if(s < 4) return 0;
- for(ll i = 2; i < 61; i++) {
- if(s < (1ll << i)) return sum;
- ll p = i, l = (1ll << i), r = (1ll << (i + 1)) - 1, cnt = 1;
- if(r > s) r = s;
- while(1) {
- if(l > r) break;
- if(p > l / i) {
- if(p > r / i) {
- sum += (r - l + 1) % mod * cnt % mod, sum %= mod;
- break;
- }
- else sum += (p * i - l) % mod * cnt % mod, sum %= mod;
- l = p * i;
- }
- p *= i;
- ++cnt;
- }
- }
- return sum;
- }
- void solve() {
- ll l,r;
- cin >> l >> r;
- ll ans = g(r) - g(l - 1);
- ans = (ans % mod + mod) % mod;
- cout<< (ll)ans << endl;
- }
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(NULL);
- int t;
- cin >> t;
- while(t--)
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement