QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#585281 | #9376. Game | mt666 | WA | 117ms | 3700kb | C++23 | 902b | 2024-09-23 20:06:48 | 2024-09-23 20:06:48 |
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;
ans=0;
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: 100
Accepted
time: 0ms
memory: 3648kb
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: 0
Accepted
time: 59ms
memory: 3700kb
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:
947058399 376449942 612621163 138416357 592200562 45779380 870227707 169499045 86396463 415694940 46851356 951368934 426243016 864656779 750317399 922456360 486881524 824329239 198191519 189360084 966510181 512645443 695650039 703100783 550002158 438470182 246877045 39876086 667870434 405196653 5935...
result:
ok 100000 lines
Test #3:
score: -100
Wrong Answer
time: 117ms
memory: 3580kb
input:
100000 167959139 481199252 18199423 25950409 149762920 773386884 579721198 16629525 28339910 152155823 2087506 268792718 43528658 6471925 90197530 691952768 717268783 516613092 94328992 743662288 45277106 856168102 309821265 346013425 963168258 279198849 527268921 30167950 166388455 577970339 140515...
output:
-395924882 -37534472 538996492 -100074048 -969491127 93512811 770490227 -832222172 -187447854 88725848 -111121039 -474333909 -199184287 434237042 -208487579 555475099 203547423 808126245 -503857627 160914898 417168816 61839619 -614643351 14106370 367085364 -632928 -730464428 787121905 -348626739 -37...
result:
wrong answer 1st lines differ - expected: '623291477', found: '-395924882'