QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#582213 | #9376. Game | tzw | TL | 0ms | 3624kb | C++14 | 832b | 2024-09-22 15:40:04 | 2024-09-22 15:40:05 |
Judging History
answer
#include<iostream>
#include<math.h>
#define mod 998244353
#define int long long
using namespace std;
int exgcd(int a,int b,int &x,int &y){
if(b==0){
x=1,y=0;
return a;
}
int d=exgcd(b,a%b,y,x);
y-=a/b*x;
return d;
}
int qpow(int a,int b){
int m=1;
while(b>1){
if(b%2==0){
a=a*a%mod;
b/=2;
}
else{
m=m*a%mod;
a=a*a%mod;
b/=2;
}
}
return a*m%mod;
}
signed main(){
int t;
cin>>t;
while(t--){
int x,y,a0,a1,b,u,v;
int ans=0;
cin>>x>>y>>a0>>a1>>b;
exgcd(a0+a1,mod,u,v);
int p=1;
while(1){
if(x>=y){
x-=y;
(p*=u)%=mod;
(ans+=p*a0)%=mod;
(p*=a1)%=mod;
if(!x) break;
}
else{
y-=x;
(p*=a0)%=mod;
(p*=u)%=mod;
}
}
//cout<<ans<<' '<<q<<endl;
cout<<(ans+mod)%mod<<endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
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
Time Limit Exceeded
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...