QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#585466 | #9376. Game | lzy | WA | 172ms | 3716kb | C++14 | 1.2kb | 2024-09-23 20:54:22 | 2024-09-23 20:54:23 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
const int N=1e6+10;
const ll mod=998244353;
ll qpow(ll a,ll b){
ll sum=1;
a%=mod;
while(b){
if(b&1)
sum=sum*a%mod;
a=a*a%mod;
b>>=1;
}
return sum%mod;
}
int main()
{
IOS;
int T;
cin>>T;
while(T--)
{
ll x,y;
cin>>x>>y;
ll a0,a1,b;
cin>>a0>>a1>>b;
ll p0,p1;
p0=(a0*(qpow(a0+a1,mod-2)))%mod;
p1=(a1*(qpow(a0+a1,mod-2)))%mod;
if(x==y)
{
cout<<p0<<"\n";
}
else
{
ll temp=0;
ll p=1;
while(x!=y)
{
if(x>y)
{
ll t=x/y;
x-=(t*y);
ll p3=(1-qpow(p1,t)+mod)%mod;
p3=(p3*(qpow((1-p1+mod)%mod,mod-2)%mod))%mod;
p3=(p3*p0)%mod;
ll p4=qpow(p1,t)%mod;
if(x==0)
{
p=(p*p3)%mod;
cout<<(p+temp)%mod<<"\n";
break;
}
p=(p*p4)%mod;
temp=(temp+p3)%mod;
}
else if(x<y)
{
ll t=(y-1)/x;
ll p3=qpow(p0,t);
p=(p3*p)%mod;
y-=(t*x);
if(x==y)
{
cout<<(((p*p0)%mod)+temp)%mod<<"\n";
break;
}
}
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3704kb
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: 55ms
memory: 3592kb
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: 172ms
memory: 3716kb
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:
194561192 125379065 58348483 835945559 339291799 401583773 662109439 906065410 25854609 537430038 120448747 832095970 914013517 876551436 798732516 982957131 685556866 854135893 348757503 524635905 347754983 599122640 209627 637278639 667379013 550001044 231999533 22906099 333078323 971238995 542572...
result:
wrong answer 1st lines differ - expected: '623291477', found: '194561192'