QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#602232 | #9376. Game | Retr00 | WA | 168ms | 3632kb | C++20 | 1.2kb | 2024-09-30 21:25:56 | 2024-09-30 21:26:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
ll qpow(ll a, ll n)
{
ll res = 1;
a %= MOD;
while (n)
{
if (n & 1)
res = res * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return res;
}
int main()
{
int T;
cin >> T;
while (T--)
{
ll x, y, a0, a1, b, kk = 1, bb = 0;
cin >> x >> y >> a0 >> a1 >> b;
kk = 1, bb = 0;
ll k1 = (a0 + a1) * qpow(a1, MOD - 2) % MOD;
ll k2 = (a0 + a1) * qpow(a0, MOD - 2) % MOD;
while (x != y)
{
if (x > y)
{
ll n = x / y + x % y - 1;
ll qp = qpow(k1, n);
kk = qp * kk % MOD;
bb = (1 - (1 - bb) * qp + MOD) % MOD;
x = x - n * y;
}
else if (x < y)
{
ll n = y / x + y % x - 1;
ll qp = qpow(k2, n);
kk = qp * kk % MOD;
bb = qp * bb % MOD;
y = y - n * x;
}
}
ll ans = (a0 * qpow(a0 + a1, MOD - 2) - bb + MOD) * qpow(kk, MOD - 2) % MOD;
cout << ans << '\n';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3632kb
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: -100
Wrong Answer
time: 168ms
memory: 3572kb
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:
-290303674 161698878 612621163 -826942058 592200562 525300864 870227707 169499045 77133363 415694940 -929452927 628373168 426243016 864656779 750317399 806703725 486881524 -328354250 198191519 189360084 966510181 512645443 695650039 -483348449 550002158 600605589 -401063490 -542710715 667870434 2291...
result:
wrong answer 1st lines differ - expected: '947058399', found: '-290303674'