#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 60, M = 200;
long long dp_small[M + 8], dp[64], c[M * 2 + 8];
vector<int> adj[M + 8];
int d[M + 8];
void DFS(int u, int p) {
d[u] = d[p] + 1;
for (int v : adj[u]) if (v != p) DFS(v, u);
}
long long res_pw;
long long qpow(long long x, long long expo, long long m) {
res_pw = 1; x %= m;
while (expo) {
if (expo & 1) res_pw = res_pw * x % m;
x = x * x % m;
expo >>= 1;
}
return res_pw;
}
void prep() {
d[0] = -1;
for (int n = 1; n <= M; ++n) {
for (int i = 1; i <= n; ++i) {
if (i / 2 > 0) adj[i].push_back(i / 2);
if (i * 2 <= n) adj[i].push_back(i * 2);
if (i * 2 + 1 <= n) adj[i].push_back(i * 2 + 1);
}
for (int r = 1; r <= n; ++r) {
DFS(r, 0);
for (int i = 1; i <= n; ++i) ++c[d[i]];
int sf = 0;
for (int i = n + n; i; --i) {
sf += c[i];
dp_small[n] = (dp_small[n] + qpow(2, sf, mod) - 1) % mod;
}
memset(c, 0, sizeof c);
}
dp_small[n] = dp_small[n] * qpow(qpow(2, n, mod) - 1, mod - 2, mod) % mod;
for (int i = 1; i <= n; ++i) adj[i].clear();
}
for (int h = 1; h <= N; ++h) {
// n = 2^h - 1
for (int i = 0; i < h; ++i) {
for (int j = i; j >= 0; --j) {
c[i - j] = (c[i - j] + 1) % (mod - 1);
for (int k = j + 1; k < h; ++k) {
c[i - j + k - j] = (c[i - j + k - j] + qpow(2, k - j - (j < i), mod - 1)) % (mod - 1);
}
}
long long sf = 0, cur = 0;
for (int i = h + h; i; --i) {
sf = (sf + c[i]) % (mod - 1);
cur = (cur + qpow(2, sf, mod) - 1) % mod;
}
dp[h] = (dp[h] + cur * ((1LL << i) % mod)) % mod;
memset(c, 0, sizeof c);
}
dp[h] = dp[h] * qpow(qpow(2, (1LL << h) - 1, mod) - 1, mod - 2, mod) % mod;
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
prep();
int tc; long long n; cin >> tc;
while (tc--) {
cin >> n;
if (n <= M) cout << dp_small[n] << '\n';
else cout << dp[__lg(n) + 1] << '\n';
}
}
| # | 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... |