QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#580865 | #9376. Game | zfasion | WA | 409ms | 3564kb | C++14 | 1.5kb | 2024-09-22 00:26:16 | 2024-09-22 00:26:23 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int __int128
const int N=3e5+5,M=998244353;
int read()
{
int x=0,f=1;
char ch=getchar();
while(ch>'9'||ch<'0')
{
f=-1;ch=getchar();
}
while(ch<='9'&&ch>='0')
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
void write(int x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x>=10)
write(x/10);
putchar(x%10+'0');
}
int qpow(int m,int n)
{
int x=m,ans=1;
while(n)
{
if(n&1)
{
ans=(ans*x)%M;
}
n>>=1;
x=(x*x)%M;
}
return ans;
}
int inv(int x)
{
return qpow(x,M-2);
}
signed main()
{
int t,x,y,a,b,p;
t=read();
while(t--)
{
x=read(),y=read(),a=read(),b=read(),p=read();
p=a+b;
p%=M;
a=a*inv(p)%M,b=b*inv(p)%M;
//int res1=(a*(qpow(b,u+1)-1)%M)*inv(b-1)%M;
int ans=1;
function <int(int,int)> c=[&](int x,int y)->int
{
if(x>=y)
{
int u=((x-y)/y);
int res1=(a*(qpow(b,u+1)-1)%M*inv(b-1)%M)%M;
x%=y;
if(!x)
{
return (res1)%M;
}
// cout<<res1<<"a\n";
int res=res1+b*c(x,y)%M;
return ((res%M)+M)%M;
}
else if(x==y)
{
return a;
}
else
{
int d=(y-x)/x+bool((y-x)%x);
int q=qpow(a,d);
y%=x;
if(!y)
{
return (a*q)%M;
}
int res=q*c(x,y)%M;
return (res%M+M)%M;
}
} ;
int res=c(x,y);
write((res%M+M)%M);
putchar('\n');
// cout<<(res1%M+M)%M<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3540kb
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: 94ms
memory: 3564kb
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: 409ms
memory: 3524kb
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:
271059748 313509270 684143117 602445657 218611975 661588519 577704583 912891548 132230529 27329369 977229972 279912089 157398135 770404338 148270822 682035858 537580200 613186660 842014609 346410072 970310877 963447298 359567789 42807337 52220280 398023605 303597936 60296363 794540937 319512927 3300...
result:
wrong answer 1st lines differ - expected: '623291477', found: '271059748'