QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#585271 | #9376. Game | mt666 | WA | 0ms | 3684kb | C++23 | 893b | 2024-09-23 20:03:29 | 2024-09-23 20:03:30 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define INF 2e18
#define int long long
const int N=1e6+10,mod=998244353;
int x,y,p0,p1,t;
int ans;
int qmi(int a,int b)
{
int res=1;
while(b)
{
if(b&1) res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res%mod;
}
void dfs(int a,int b,int last)
{
if(a==b)
{
ans=(ans+last*p0%mod)%mod;
return;
}
if(a<b)
{
int k=(b-1)/a;
last=last*qmi(p0,k);
dfs(a,b-k*a,last);
}
else
{
int k=(a-1)/b;
ans=(ans+last*(1-qmi(p1,k)+mod)%mod)%mod;
last=last*qmi(p1,k)%mod;
dfs(a-k*b,b,last);
}
}
void solve()
{
cin>>x>>y>>p0>>p1>>t;
t=p0+p1;
p0=p0*qmi(t,mod-2)%mod;
p1=p1*qmi(t,mod-2)%mod;
dfs(x,y,1);
cout<<ans%mod<<endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int _;
cin>>_;
while(_--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3684kb
input:
3 1 1 2 2 6 1 3 2 3 6 3 4 7 3 15
output:
499122177 411276674 632188150
result:
wrong answer 2nd lines differ - expected: '910398850', found: '411276674'