#include <bits/stdc++.h>
using namespace std;
#define int ll
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1e9 + 100;
const ll LINF = 1e18 + 100;
#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define fr first
#define sc second
#define all(x) (x).begin(), (x).end()
#define endl '\n'
const int LOGN = 62;
int q;
ll n;
int k;
ll outdp[LOGN][2 * LOGN];
ll dp[LOGN][2 * LOGN];
ll ans;
ll poww(ll a, ll b)
{
a %= mod;
ll res = 1;
while (b)
{
if (b & 1) res = res * a % mod;
a = a * a % mod;
b /= 2;
}
return res;
}
inline void tcase(void)
{
memset(dp, 0, sizeof(dp));
memset(outdp, 0, sizeof(outdp));
ans = 0;
cin >> n;
k = __builtin_popcountll(n);
FOR(i, 1, k)
{
FOR(x, 1, 2 * LOGN)
{
outdp[i][x] = outdp[i - 1][x - 1] + (x >= 2 && i + x - 2 < k ? (1ll << (x - 2)) : 0) + (x == 1);
}
//dbg(i);
//dbgr(outdp[i], outdp[i] + 10);
}
//dbg("========================\n\n");
FOR(i, 0, k)
{
dp[i][2 * LOGN - 1] = outdp[i][2 * LOGN - 1];
for (int x = 2 * LOGN - 2; x >= 0; x--) dp[i][x] = dp[i][x + 1] + outdp[i][x] + (i + x < k ? (1ll << x) : 0);
// dbg(i);
// dbgr(dp[i], dp[i] + 10);
}
FOR(i, 0, k)
{
ll val = 0;
FOR(x, 1, 2 * LOGN - 1) val = (val + ((ll)x * (poww(2, dp[i][x]) - poww(2, dp[i][x + 1])) % mod)) % mod;
ans = (ans + val * ((1ll << i) % mod) % mod) % mod;
}
// dbg(ans);
ans = ans * poww((poww(2, n) - 1) % mod, mod - 2) % mod;
ans = (mod + ans % mod) % mod;
cout << ans << endl;
}
int32_t main(void)
{
fast_io;
cin >> q;
while (q--) tcase();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
161 ms |
408 KB |
Output is correct |
2 |
Correct |
184 ms |
412 KB |
Output is correct |
3 |
Correct |
168 ms |
452 KB |
Output is correct |
4 |
Correct |
147 ms |
424 KB |
Output is correct |
5 |
Correct |
178 ms |
416 KB |
Output is correct |
6 |
Correct |
177 ms |
412 KB |
Output is correct |
7 |
Correct |
152 ms |
332 KB |
Output is correct |
8 |
Correct |
168 ms |
432 KB |
Output is correct |
9 |
Correct |
154 ms |
420 KB |
Output is correct |
10 |
Correct |
169 ms |
416 KB |
Output is correct |
11 |
Execution timed out |
3070 ms |
460 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |