QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#584571#9376. GameYu_mxRE 0ms0kbC++141.4kb2024-09-23 15:20:092024-09-23 15:20:10

Judging History

你现在查看的是最新测评结果

  • [2024-09-23 15:20:10]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-23 15:20:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'

const int MOD = 998244353;

ll qmi(ll a,ll k,ll p){
	ll res = 1%p;
	while(k){
		if(k&1) res = 1LL*res*a%p;
		k >>= 1;
		a = 1LL*a*a%p;
	}
	return res;
} 

ll lcm(ll xx,ll yy){
	return yy/__gcd(xx,yy)%MOD*xx;
}

void solve(){
	ll x,y,px,py,b,ansfz=0,ansfm=1;
	ll fz0 = 1,fm0 = 1;
	cin>>x>>y;
	cin>>px>>py>>b;
	b = px+py;
	while(y){
		ll fz, fm;
		ll fz1 = fz0, fm1 = fm0; 
		ll n;
		if(x>y){
			n = (x-1)/y;
			x -= n*y;
			fz0 = fz0*qmi(py,n,MOD)%MOD;
			fm0 = fm0*qmi(b,n,MOD)%MOD;
			fz = px*(qmi(b,n,MOD)%MOD+MOD-qmi(py,n,MOD)%MOD)%MOD;
			fm = (qmi(b,n+1,MOD)+MOD-py*qmi(b,n,MOD)%MOD)%MOD;
		}
		else{
			n = y/x;
			y -= n*x;
			fz0 = fz0*qmi(px,n,MOD)%MOD;
			fm0 = fm0*qmi(b,n,MOD)%MOD;
			if(y!=0) fz = 0;
			else{
				fz = qmi(px,n,MOD)%MOD;
				fm = qmi(b,n,MOD)%MOD;
			}
		}
		
		ll tt = __gcd(fz,fm);
		fz /= tt;
		fm /= tt;
		fz = fz*fz1%MOD;
		fm = fm*fm1%MOD;
		tt = lcm(ansfm,fm);
		//cout<<x<<' '<<y<<' '<<fz<<' '<<fm<<endl;
		ansfz = (tt/ansfm*ansfz%MOD+tt/fm*fz%MOD)%MOD;
		ansfm = tt%MOD;
		tt =__gcd(fz0,fm0);
		fz0 /= tt;
		fm0 /= tt;
	}  
	ll ans;
	ans = ansfz%MOD*qmi(ansfm,MOD-2,MOD)%MOD;
	//cout<<ansfz<<' '<<ansfm<<endl;
	cout<<ans<<endl; 
} 

int main(){
	ios;
	ll T;cin>>T;while(T--)
	solve();
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

3
1 1
2 2 6
1 3
2 3 6
3 4
7 3 15

output:


result: