QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#598074 | #9376. Game | mogen | WA | 816ms | 3640kb | C++14 | 1.4kb | 2024-09-28 20:24:57 | 2024-09-28 20:24:59 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int x,y,a,b,c;
const int mod=998244353;
int ksm(int base,int sum)
{
int ans=1;
while(sum)
{
if(sum%2)
ans*=base;
base*=base;
sum/=2;
ans%=mod;
base%=mod;
}
return ans;
}
int nt(int o1,int p1)
{
return ((ksm(p1,mod-2)%mod*o1)%mod);
}
int gd(int o,int p)//分别的筹码
{
if(p==0)
return 1;
if(o>p)
{
int o1=nt(a,c);
int p1=nt(b,c);
o1%=mod;
p1%=mod;
int ss=o/p;
if(o%p==0)
ss--;
int ssum=0;
ssum=(o1*(1-(ksm(p1,ss)%mod)))%mod;
ssum=(ssum*(ksm(1-p1,mod-2)))%mod;
int sum=o%p;
int num=ksm(p1,ss)%mod;
if(o%p==0)
num*=o1,
num%=mod;
return (ssum+num*gd(o,sum))%mod;
}
else if(o==p)
{
int o1=nt(a,c);
int p1=nt(b,c);
return o1%mod;
}
else
{
int ci=p/o;
int o1=nt(a,c)%mod;
o1=ksm(o1,ci);
o1%=mod;
return (o1*(gd(o,p%o)%mod))%mod;;
}
}
void solve()
{
cin >> x >> y >> a >> b >> c;
c=a+b;
int ans=0;
ans=gd(x,y);
cout <<ans<<'\n';
}
signed main()
{
int t;
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
while( t -- )
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
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: 54ms
memory: 3600kb
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: 816ms
memory: 3604kb
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:
455823514 916375143 722114866 930784660 424855066 38693323 433344493 656841429 464368624 738417837 845824780 107801744 167523102 758578032 344726718 283544291 624680206 703563557 843981373 777436490 767333564 719277442 93444831 196689545 797554348 343119136 359984417 966159992 503052552 477929881 30...
result:
wrong answer 1st lines differ - expected: '623291477', found: '455823514'