QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#586254 | #9376. Game | explorerxx | WA | 37ms | 3880kb | C++14 | 1.6kb | 2024-09-24 09:58:45 | 2024-09-24 09:58:46 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+100;
const int Mod=998244353;
int qr(){
int x=0,f=0;char ch=0;
while(!isdigit(ch)){f|=ch=='-';ch=getchar();}
while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
return f?-x:x;
}
long long qkpow(long long a,long long b){
long long res=1;
while(b){
if(b&1) res=(res*a)%Mod;
a=(a*a)%Mod,b>>=1;
}
return res%Mod;
}
int gcd(int a,int b){
return b?gcd(b,a%b):a;
}
int main(){
int T=qr();
while(T--){
int x=qr(),y=qr(),a0=qr(),a1=qr(),b=qr();
int p;
int ans;
bool flag=0;
if(x>y){
flag=1;
swap(x,y),swap(a0,a1);
}
int m=1ll*a0%Mod*qkpow(a0+a1,Mod-2)%Mod,n=1ll*a1*qkpow(a0+a1,Mod-2)%Mod;
if(x==y){
ans=m;
printf("%d\n",ans);
continue;
}if(x<y&&y%x==0){
p=y/x;
ans=qkpow(m,p);
printf("%d\n",ans);
continue;
}else{
p=(y-1)/x;
int z=(y-x)%x;
ans=qkpow(m,p+1);
int u=0,v=1;
while(x!=gcd(x,z)){
u++;
if(x>2*z) x-=z,(ans+=1ll*qkpow(m,p+v)*qkpow(n,u)%Mod)%=Mod;
else{
x-=z,v=p+(z-1)/x;
(ans+=1ll*qkpow(n,u)*qkpow(m,p+v)%Mod)%=Mod,z-=x;
}
}
}
if(flag){
ans=(1-ans+Mod)%Mod;
}
printf("%d\n",ans);
}
return 0;
}
/*
3
1 1
2 2 6
1 3
2 3 6
3 4
7 3 15
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3788kb
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: -100
Wrong Answer
time: 37ms
memory: 3880kb
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 952464974 870227707 169499045 911847891 415694940 951392998 951368934 426243016 864656779 750317399 75787994 486881524 824329239 198191519 189360084 966510181 512645443 695650039 295143571 550002158 559774172 246877045 39876086 667870434 405196653 59...
result:
wrong answer 6th lines differ - expected: '45779380', found: '952464974'