QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#608045 | #9381. 502 Bad Gateway | Saton | WA | 0ms | 3616kb | C++20 | 1.7kb | 2024-10-03 18:03:15 | 2024-10-03 18:03:16 |
Judging History
answer
///by Saton.
#include<bits/stdc++.h>
#define PI acos(-1)
#define fi first
#define se second
#define sz(a) ((int)a.size())
#define all(a) a.begin(), a.end()
#define LL long long
#define ll __int128
#define DD double double
#define LD long double
#define rep(i,a,b) for(LL i = (a);i <= (b);i ++)
#define lep(i,a,b) for(LL i = (a);i >= (b);i --)
#define FLUSH fflush(stdout)
using namespace std;
const int N = 2e5 + 10,mod = 998244353,P = 131;
const LL inf = 1e9+10,INF = 1e18+10;
typedef pair<int,int> PII;
typedef pair<LL,int> PLI;
LL qmi(LL a,LL b,LL p) {LL res = 1;while(b) {if(b&1) res = (LL)res*a%p;a = (LL)a*a%p;b >>= 1;}return res%p;}
LL x,y,a0,a1,a,b,p0,p1;
LL ans1,ans2;
void dfs(LL x,LL y,LL p) {
// cout << x << " " << y << " " << p << '\n';
if(x==y) {
ans1 = (ans1 + p0*p%mod) % mod;
ans2 = (ans2 + p1*p%mod) % mod;
return;
}
else if(x>y) {
LL t = (x-1)/y;
LL pr = qmi(p1,t,mod);
ans1 = (ans1 + p*(1-pr+mod)%mod) % mod;
x -= y*t;
p = p*pr%mod;
dfs(x,y,p);
}
else {
LL t = (y-1)/x;
LL pr = qmi(p0,t,mod);
ans2 = (ans2 + p*(1-pr+mod)%mod) % mod;
y -= x*t;
p = p*pr%mod;
dfs(x,y,p);
}
}
void solve() {
cin >> x >> y >> a0 >> a1 >> b;
a = (a0+a1)%mod;
p0 = a0*qmi(a,mod-2,mod);
p1 = a1*qmi(a,mod-2,mod);
ans1 = ans2 = 0;
dfs(x,y,1);
cout << ans1 << '\n';
}
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T;
cin >> T;
while(T --) {
solve();
}
// solve();
return 0;
}
/* /\_/\
* (= ._.)
* / > \>
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3616kb
input:
3 1 2 3
output:
1 1 1
result:
wrong answer 1st lines differ - expected: '1 1', found: '1'