-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path037-suspicious-logarithms.cpp
More file actions
50 lines (49 loc) · 1.2 KB
/
Copy path037-suspicious-logarithms.cpp
File metadata and controls
50 lines (49 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* Suspicious logarithms [1891D]
* Problem: https://codeforces.com/problemset/problem/1891/D
* Verdict: ACCEPTED Solved: 2023-12-20
* Language: C++20 (GCC 11-64)
* Runtime: 935 ms Memory: 1200 KB
* Tags: binary search, brute force, math
* Author: BidoTeima
* Source: https://codeforces.com/contest/1891/submission/238151151
*/
#include <bits/stdc++.h>
using ll = long long;
using ull = uint64_t;
using namespace std;
ull mod = 1e9 + 7;
ull f(ull base, ull l, ull r){
ull ret = 0;
ull a,b;
for(ull x = base, i = 1; ; i++){
if(x * base - 1 < l) goto breh;
a = max(x, l);
b = min(x * base - 1, r);
if(a <= b) ret += ((b - a + 1)%mod*i%mod)%mod;
ret %= mod;
breh:
if(x * base <= r) x *= base;
else break;
}
return ret;
}
int main()
{
int q;
cin>>q;
while(q--){
ll l,r;
cin>>l>>r;
ll ans = 0;
for(ll i = 2, j = 1; i <= r; i <<= 1, j++){
if(2 * i - 1 < l) continue;
ll a = max(i, l);
ll b = min(2 * i - 1, r);
if(a <= b) ans += f(j, a, b);
ans %= mod;
}
cout<<ans<<'\n';
}
return 0;
}