QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#580566 | #9381. 502 Bad Gateway | REN5511 | WA | 0ms | 3604kb | C++14 | 2.2kb | 2024-09-21 22:29:01 | 2024-09-21 22:29:01 |
Judging History
answer
#include <iostream>
#include <concepts>
using namespace std;
#define endl '\n';
#define ll long long
int mod = 998244353;
void exgcd(ll a, ll b, ll& x, ll& y)
{
if (b == 0)
{
x = 1, y = 0;
return;
}
exgcd(b, a % b, y, x);
y -= a / b * x;
}
ll inv(ll a)
{
ll b = mod, x = 1, y = 0;
while (b)
{
ll t = a / b;
a -= t * b;
x -= t * y;
swap(a, b);
swap(x, y);
}
return (x % mod + mod) % mod;
}
ll qpow(ll x, ll b)
{
ll ans = 1, k = x;
k %= mod;
while (b != 0)
{
if (b & 1)
{
ans = ans * k % mod;
}
k = k % mod * k % mod;
b /= 2;
}
return ans;
}
ll ans = 0;
void dfs(ll a, ll b, ll n, ll m, ll last)
{
if (a == b)
{
ans += last % mod * n % mod * inv(n + m) % mod;
//ans%=mod;
}
else if (a < b)
{
if (b % a == 0)
{
ans += last*qpow(n * inv(n + m) % mod, b / a);
ans %= mod;
}
else
{
dfs(a, b % a, n, m, last * qpow(n * inv(n + m) % mod, b / a) % mod);
}
}
else
{
if (a % b == 0)
{
ll q = n % mod * inv(n + m) % mod;
ans += ((qpow(m + n, a / b) - qpow(m, a / b) + mod) % mod * qpow(qpow(m + n, a / b), mod - 2) % mod) % mod * (n + m) % mod * inv(n) % mod * last % mod * n % mod * inv(n + m) % mod;
ans %= mod;
}
else
{
ll q = n % mod * inv(n + m) % mod;
ans += ((qpow(m + n, a / b) - qpow(m, a / b) + mod) % mod * qpow(qpow(m + n, a / b), mod - 2) % mod) % mod * (n + m) % mod * inv(n) % mod * last % mod * n % mod * inv(n + m) % mod;
ans %= mod;
dfs(a % b, b, n, m, last*qpow(m * inv(n + m) % mod, a / b) % mod);
}
}
}
int main()
{
int t;
cin >> t;
while (t--)
{
ans = 0;
ll a, b;
ll n, m, temp;
cin >> a >> b >> n >> m >> temp;
dfs(a, b, n, m, 1);
ans %= mod;
cout << ans << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3604kb
input:
3 1 2 3
output:
303348953 303348953 303348953
result:
wrong answer 1st lines differ - expected: '1 1', found: '303348953'