QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#583199 | #9376. Game | wangwx | TL | 0ms | 0kb | C++14 | 1.6kb | 2024-09-22 18:56:10 | 2024-09-22 18:56:12 |
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mxn=2e3+5,inf=1e9+7,mod=998244353;
int a,b,c;
int t;
int cpa,cpb;
int ksm(int cnta,int cntb){
int res=1;
while(cntb){
if(cntb&1) res=res*cnta%mod;
cntb>>=1;
cnta=cnta*cnta%mod;
}
return res;
}
int btgcd(int cpa,int cpb,int fz,int fm){
if(cpb==0){
int cnt=fz*(ksm(fm,mod-2)%mod)%mod;
return cnt;
}
else if(cpa==cpb){
int cnt=fz*a%mod* ( ksm(fm*c%mod,mod-2)%mod )%mod;
return cnt;
}else{
if(cpb>cpa){
int zc=cpb/cpa;
fz=fz*ksm(a,zc)%mod;
fm=fm*ksm(c,zc)%mod;
btgcd(cpa,cpb%cpa,fz,fm);
}else{
if(cpa%cpb==0){
int zc=cpa/cpb;
fz=fz* ( ksm(c,zc)-ksm(b,zc)+mod)%mod;
fm=fm* ksm(c,zc)%mod;
int cnt= fz*( ksm(fm,mod-2)%mod)%mod;
return cnt;
}else{
int zc=cpa/cpb;
fz=fz* ( ksm(c,zc)-ksm(b,zc)+mod)%mod;
fm=fm* ksm(c,zc)%mod;
int cnt= fz*( ksm(fm,mod-2)%mod)%mod;
int zccnt=btgcd( cpa-cpb*(zc-1),cpb,fz*ksm(b,zc)%mod,fm*ksm(c,zc)%mod);
return ((cnt+zccnt)%mod+mod)%mod;
}
}
}
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>t;
while(t--){
cin>>cpa>>cpb;
cin>>a>>b>>c;
c=a+b;
int ans=btgcd(cpa,cpb,1,1);
cout<<ans<<'\n';
}
return 0;}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
3 1 1 2 2 6 1 3 2 3 6 3 4 7 3 15