#include <bits/stdc++.h>
using i64 = long long;
constexpr i64 mod = 1000000007;
i64 nmr(i64 a) {
a %= mod;
if (a < 0) a += mod;
return a;
}
i64 add(i64 a, i64 b) { return nmr(a + b) % mod; }
i64 mul(i64 a, i64 b) { return nmr(a) * nmr(b) % mod; }
void add_m(i64 &a, i64 b) { a = add(a, b); }
void mul_m(i64 &a, i64 b) { a = mul(a, b); }
i64 inv(i64 x) {
i64 a = x, b = mod, u = 1, v = 0, t = 0;
while (b > 0) {
t = a / b;
a -= t * b;
u -= t * v;
std::swap(a, b);
std::swap(u, v);
}
return nmr(u);
}
i64 pow(i64 a, i64 n) {
i64 ret = 1;
while (n != 0) {
if (n & 1) ret = ret * a % mod;
a = a * a % mod;
n >>= 1;
}
return ret;
}
void solve() {
i64 N; std::cin >> N;
// N = 2 ^ k - 1
i64 k = 0;
while ((1ll << k) - 1 < N) ++k;
//assert((1ll << k) - 1 == N);
i64 res = 0;
for (i64 d = 0; d < k; ++d) {
i64 ms = 1ll << d;
i64 sum = 0;
for (i64 u = 0; u <= 2 * k; ++u) {
i64 count_v = 0;
for (i64 p = 0; p <= u; ++p) {
const i64 now_d = d - p;
if (now_d < 0) continue;
const i64 t = u - p;
if (now_d + t >= k) continue;
i64 c = 1ll << t;
if (p != 0 and t != 0) c /= 2;
count_v += c;
}
add_m(res, mul(mul(ms, u), add(pow(2, N - sum), mod - pow(2, N - sum - count_v))));
sum += count_v;
}
}
mul_m(res, inv(add(pow(2, N), mod - 1)));
std::cout << res << std::endl;
}
int main() {
int Q; std::cin >> Q;
while (Q--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3073 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
173 ms |
300 KB |
Output is correct |
2 |
Correct |
199 ms |
212 KB |
Output is correct |
3 |
Correct |
177 ms |
212 KB |
Output is correct |
4 |
Correct |
168 ms |
296 KB |
Output is correct |
5 |
Correct |
186 ms |
212 KB |
Output is correct |
6 |
Correct |
180 ms |
212 KB |
Output is correct |
7 |
Correct |
163 ms |
212 KB |
Output is correct |
8 |
Correct |
186 ms |
212 KB |
Output is correct |
9 |
Correct |
167 ms |
212 KB |
Output is correct |
10 |
Correct |
177 ms |
212 KB |
Output is correct |
11 |
Execution timed out |
3055 ms |
452 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3073 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3073 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |