QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#582191 | #9376. Game | bu_mo | WA | 566ms | 3948kb | C++20 | 1.3kb | 2024-09-22 15:36:17 | 2024-09-22 15:36:17 |
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3788kb
input:
3 1 1 2 2 6 1 3 2 3 6 3 4 7 3 15
output:
499122177 910398850 220911476
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 92ms
memory: 3796kb
input:
100000 1 1000000000 12980050 128257807 266126484 1 1000000000 400255084 123438563 768881284 1000000000 1000000000 24563487 72082135 450057094 1 1000000000 56952077 40876000 193815114 1000000000 1000000000 82048274 239365585 326520865 1000000000 1 309821265 346013425 963168258 1 1 104158269 199365020...
output:
947058399 376449942 612621163 138416357 592200562 45779380 870227707 169499045 86396463 415694940 46851356 951368934 426243016 864656779 750317399 922456360 486881524 824329239 198191519 189360084 966510181 512645443 695650039 703100783 550002158 438470182 246877045 39876086 667870434 405196653 5935...
result:
ok 100000 lines
Test #3:
score: -100
Wrong Answer
time: 566ms
memory: 3948kb
input:
100000 167959139 481199252 18199423 25950409 149762920 773386884 579721198 16629525 28339910 152155823 2087506 268792718 43528658 6471925 90197530 691952768 717268783 516613092 94328992 743662288 45277106 856168102 309821265 346013425 963168258 279198849 527268921 30167950 166388455 577970339 140515...
output:
798082414 755882297 597143645 178519867 405333724 600824025 870727207 125606158 68757614 446313142 691993541 7424950 947158545 806930749 744703067 638511509 312098004 977233118 376794001 751260551 508028896 831141488 226184365 518762183 235523029 60739035 273612752 753038604 580528416 588461292 2175...
result:
wrong answer 1st lines differ - expected: '623291477', found: '798082414'