QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#21640 | #2842. 好图计数 | hy_zheng_zai_nei_juan# | WA | 187ms | 3840kb | C++20 | 975b | 2022-03-07 17:54:25 | 2022-05-08 03:46:07 |
Judging History
answer
#include <bits/stdc++.h>
const int N = 23334;
int n, T, mod, f[N], g[N], sum[N];
int fastpow(int x, int p) {
int r = 1;
while (p) {
if (p & 1) r = 1ll * r * x % mod;
x = 1ll * x * x % mod;
p >>= 1;
}
return r;
}
void solve() {
int inv2 = (mod + 1) >> 1;
for (int n = 1; n < N; ++n) {
if (n == 1) {
f[n] = g[n] = 1;
}
else {
__int128 total = 0;
for (int i = 1; i < n; ++i)
total += 1ll * f[i] * sum[n - i];
f[n] = 2ll * (f[n] + total % mod) * fastpow(n, mod - 2) % mod;
g[n] = 1ll * inv2 * f[n];
}
for (int i = n; i < N; i += n) {
sum[i] = (sum[i] + 1ll * n * g[n]) % mod;
if (i > n) {
f[i] = (f[i] + 1ll * n * g[n]) % mod;
}
}
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
std::cin >> T >> mod;
solve();
for (int i = 1; i <= T; ++i) {
int n;
std::cin >> n;
std::cout << f[n] << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 187ms
memory: 3840kb
input:
232 1050896131 15469 609 20 15343 18812 23 22505 19565 15762 9798 20897 20183 15 20680 3775 14113 1515 5 315 21711 7173 15222 11404 4 213 908 15283 3543 6196 369 18445 757 16449 478 1 40 42 21363 11 274 114 8679 8947 32 5465 26 894 5548 6026 22489 28 9 16568 7978 18 17 12354 25 27 12536 396 14838 88...
output:
-175632735 643128338 -177912755 -787557982 -557085983 -918995194 5676000 -101399308 -801164704 -1002815386 -550391130 -646008796 480355066 -923000816 908888178 -874014173 -826397689 63966815 92748259 -984546823 688450612 548655850 -749888863 10 661789606 329036561 1049954615 -859901317 248273329 -47...
result:
wrong answer 1st lines differ - expected: '904884594', found: '-175632735'