QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#583620#9376. GamejcybtdWA 154ms3628kbC++111.5kb2024-09-22 20:52:342024-09-22 20:52:36

Judging History

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

  • [2024-09-22 20:52:36]
  • 评测
  • 测评结果:WA
  • 用时:154ms
  • 内存:3628kb
  • [2024-09-22 20:52:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll mod = 998244353; 

ll pa, pb;

ll ksm(ll a, ll b){
	a %= mod;
	b %= mod;
	ll res = 1;
	while(b){
		if(b & 1) res = (res * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	} 
	return res;
}

//ll f(ll x, ll y){//返回awin的概率 
//	if(x <= y){
//		ll kb = y / x;
//		if(y % x == 0) return ksm(pa, kb);
//		return ksm(pa, kb) * f(x, y % x) % mod;
//	}
//	else{
//		ll kb = x / y;
//		if(x % y == 0) return (1 - ksm(pb, kb) + mod) % mod;
//		// y min calc py, 
//		ll py = ksm(pb, kb) * ((1 - f(x % y, y)) % mod + mod) % mod;
//		ll px = ((1 - py) % mod + mod) % mod;
//		return px; 
//		return ((1 - ksm(pb, kb) * ((1 - f(x % y, y) + mod) % mod) % mod + mod) % mod);
//	}
//}

ll f(ll x, ll y){
	if(x <= y){
		ll kb = y / x;
		if(y % x == 0) return ksm(pa, kb);
		return ksm(pa, kb) * f(x, y % x) % mod;
	}
	else{
		ll kb = x / y;
		if(x % y == 0){
			return ((1ll - ksm(pb, kb)) % mod + mod) % mod;
		}
		ll py = ksm(pb, kb) * (((1 - f(x % y, y)) % mod + mod) % mod) % mod;
		ll px = ((1ll - py) % mod + mod) % mod;
		return px % mod;
	}
}

void solve(){
	ll x, y;
	ll a, b, c;
	cin >> x >> y >> a >> b >> c;
	pa = a * ksm(a + b, mod - 2) % mod;
	pb = b * ksm(a + b, mod - 2) % mod; 
	cout << f(x, y) << endl;
} 

void get(ll a, ll b){
	a %= mod;
	b %= mod;
	cout << a * ksm(b, mod - 2) % mod << endl;
}

int main(){
	
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
} 

/*
1000000 1
1 1 1
444030275
*/

Details

Tip: Click on the bar to expand more detailed information

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
Wrong Answer
time: 154ms
memory: 3628kb

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:

748335608
323192958
612621163
528044714
592200562
749406445
870227707
169499045
775687297
415694940
835839043
471022311
426243016
864656779
750317399
857785388
486881524
783895931
198191519
189360084
966510181
512645443
695650039
161287374
550002158
689854153
6944159
28324312
667870434
725872296
593...

result:

wrong answer 1st lines differ - expected: '947058399', found: '748335608'