This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define oo 1e9
const int MAX = 2e18 + 8, MOD = 1e9 + 7, LOGMAX = 200;
int n;
int Hcnt[LOGMAX][LOGMAX];
int RHcnt[LOGMAX][LOGMAX];
int binpow(int a, int b){
int res = 1;
while(b){
if(b & 1) res = res * a % MOD;
b /= 2;
a = a * a % MOD;
}
return res;
}
int inv(int a){
return binpow(a, MOD - 2);
}
int ans[LOGMAX];
void solve(){
int n; cin >> n;
int LG = 0, T = 1;
while(T <= n / 2) {LG++; T *= 2;}
cout << ans[LG + 1] << '\n';
}
signed main(){
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
for(int z = 1; z < 63; z++){
n = (1ll << z) - 1;
int res = 0;
int LG = z - 1;
for(int i = 0; (1ll << i) <= n; i++){
for(int j = 0; j <= LG + i; j++){
Hcnt[i][j] = 0;
RHcnt[i][j] = 0;
}
for(int j = 0; j <= LG - i; j++){
Hcnt[i][j] = (1ll << j);
RHcnt[i][j] = (1ll << max(0ll, j - 1));
}
if(i != 0){
for(int j = 0; j <= LG + i - 1; j++){
RHcnt[i][j + 1] += RHcnt[i - 1][j];
Hcnt[i][j + 1] += RHcnt[i - 1][j];
}
}
int oth = n;
for(int j = 0; j <= LG + i; j++){
oth -= Hcnt[i][j];
res = (res + j * (binpow(2, Hcnt[i][j]) - 1 + MOD) % MOD * binpow(2, oth + i) % MOD) % MOD;
}
}
ans[z] = res * inv((binpow(2, n) - 1 + MOD) % MOD) % MOD;
}
int t; cin >> t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |