QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#582189 | #9376. Game | bu_mo | WA | 0ms | 3836kb | C++20 | 1.3kb | 2024-09-22 15:36:03 | 2024-09-22 15:36:03 |
Judging History
answer
#include <bits/stdc++.h>
const int mod = 998244353;
int qpow(int a, int b) {
int ans = 1, base = a;
while (b) {
if (b & 1) ans = 1ll * ans * base % mod;
base = 1ll * base * base % mod;
b >>= 1;
}
return ans;
}
int T, x, y, fz, fm;
int solve(int x, int y, int cnt1, int cnt2) {
std::cout << x << " " << y << " " << cnt1 << " " << cnt2 << '\n';
if (y == 0) return (1ll * qpow(fz, cnt1) * qpow(qpow(fm, cnt1), mod - 2) % mod) * (1ll * qpow(fm - fz, cnt2) * qpow(qpow(fm, cnt2), mod - 2) % mod) % mod;
if (x == 0) return 0;
if (x >= y) {
int ad = (x - 1) / y;
int prt1 = (1ll * qpow(fz, cnt1 + 1) * qpow(qpow(fm, cnt1 + 1), mod - 2) % mod) * (1ll * qpow(fm - fz, cnt2) * qpow(qpow(fm, cnt2), mod - 2) % mod) % mod;
int prt2 = (1ll * fm * qpow(fz, mod - 2) % mod - 1ll * qpow(fm - fz, ad + 1) * qpow(1ll * fz * qpow(fm, ad) % mod, mod - 2) % mod + mod) % mod;
return (1ll * prt1 * prt2 % mod + solve(x % y, x, cnt1, cnt2 + ad)) % mod;
} else return solve(x, y % x, cnt1 + y / x, cnt2);
}
int main() {
scanf("%d", &T);
while (T--) {
int tmp;
scanf("%d %d", &x, &y);
scanf("%d %d %d", &fz, &fm, &tmp);
fm += fz;
if (fz == 0) puts("0");
else printf("%d\n", solve(x, y, 0, 0));
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3836kb
input:
3 1 1 2 2 6 1 3 2 3 6 3 4 7 3 15
output:
1 1 0 0 0 1 0 0 499122177 1 3 0 0 1 0 3 0 910398850 3 4 0 0 3 1 1 0 0 3 1 2 220911476
result:
wrong answer 1st lines differ - expected: '499122177', found: '1 1 0 0'