#include <bits/stdc++.h>
#define int __int128
typedef long long ll;
using namespace std;
const int inf = 1e18;
int sum[60], s[60];
int read()
{
int w = 0, h = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-')
h = -h;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
w = w * 10 + ch - '0';
ch = getchar();
}
return w * h;
}
void write(int x)
{
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
void writeln(int x)
{
write(x);
puts("");
}
void writech(int x)
{
write(x);
putchar(' ');
}
const int mod = 1e9 + 7;
int qpow(int a, int b){
int res = 1;
while(b){
if(b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
int cal(int l, int r, int t){//在x属于[l, r]的区间内,g(x)的和
int res = 0;
//int st_g = log(double(l)) / log(double(t));
//log精度不够
int base = t;
for(int p = 1; p <= 60; p++){
int L = max(l, base), R = min(r, base * t - 1);
if(base > r) break;
if(L <= R) res = (res + p * (R - L + 1)) % mod;
base = base * t;
}
return res;
}
void solve()
{
int l = read(), r = read();
int lt = __lg(ll(l)), rt = __lg(ll(r));//用log2()会wa
if(lt == rt) writeln((cal(l, r, lt)) % mod);
else{
int L = (1LL << lt), R = (1LL << (rt + 1)) - 1;
R = min(R, inf);
writeln(((sum[rt] - sum[lt - 1] - cal(L, l - 1, lt) - cal(r + 1, R, rt)) % mod + mod) % mod);
}
}
signed main()
{
int T = read();
//T = 0;
for(int t = 2; t <= 59; t++){
int l = (1LL << t), r = (1LL << (t + 1)) - 1;
r = min(r, inf);
int res = cal(l, r, t) % mod;
sum[t] = (sum[t - 1] + res) % mod;//求前缀和
}
while (T--)
solve();
return 0;
}
cf_907_div2_D. Suspicious logarithms
最新推荐文章于 2024-09-12 19:02:20 发布