QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#584432 | #9376. Game | Magicpjl | WA | 0ms | 3624kb | C++23 | 1.2kb | 2024-09-23 14:11:59 | 2024-09-23 14:12:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll md=998244353;
ll pw(ll x,ll p)
{
if(p==0)return 1;
if(p==1)return x;
ll t=pw(x,p/2);
return t*t%md*pw(x, p%2)%md;
}
ll gcd(ll x, ll y){
if(y != 0)return x;
return gcd(y, x%y);
}
int main(){
int tt;
cin>>tt;
while(tt--){
ll x, y, a0, a1, b;
cin>>x>>y>>a0>>a1>>b;
if(a0 == 0) {
cout<<0<<"\n";
continue;
}
else if(a1 == 0) {
cout<<1<<"\n";
continue;
}
ll p = 1, ans = 0;
ll p0 = (a0 * pw(a0 + a1, md - 2))% md, p1 = (a1 * pw(a0 + a1, md - 2)) % md;
x /= gcd(x, y);
y /= gcd(x, y);
auto calc = [&](auto self, ll x, ll y) -> void{
//cout<<x<<" "<<y<<endl;
if(x == 1){
ans += (p * pw(p0, y))% md;
ans %= md;
return;
}
else if(y == 1){
ans += (p * ((1 + md - pw(p1, x)) % md))% md;
ans %= md;
return;
}
if(x > y){
ll n = x / y;
ans += (p * ((1 + md - pw(p1, n) % md)))% md;
ans %= md;
p *= pw(p1, n);
p %= md;
x = x % y;
self(self, x, y);
}
else{
ll n = y / x;
p *= pw(p0, n);
p %= md;
y = y % x;
self(self, x, y);
}
};
calc(calc, x, y);
cout<<ans<<"\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3624kb
input:
3 1 1 2 2 6 1 3 2 3 6 3 4 7 3 15
output:
499122177 910398850 717038919
result:
wrong answer 3rd lines differ - expected: '220911476', found: '717038919'