Submission #635355

#TimeUsernameProblemLanguageResultExecution timeMemory
635355CyanmondParty (INOI20_party)C++17
0 / 100
3073 ms452 KiB
#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(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...