QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#584451#9376. GameMagicpjlWA 187ms3636kbC++231.2kb2024-09-23 14:19:432024-09-23 14:19:44

Judging History

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

  • [2024-09-23 14:19:44]
  • 评测
  • 测评结果:WA
  • 用时:187ms
  • 内存:3636kb
  • [2024-09-23 14:19:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 1000010;
const ll md=998244353;
ll pw(ll x,ll p)
{
	if(p==0)return 1;
	if(p==1)return x;
	ll t=pw(x,p/2);
	return t*t%md*pw(x, p%2)%md;
}
ll gcd(ll x, ll y){
	if(!y)return x;
	return gcd(y, x%y);
}
int main(){
	int tt;
	cin>>tt;
	while(tt--){
		ll x, y, a0, a1, b;
		cin>>x>>y>>a0>>a1>>b;
		if(a0 == 0) {
			cout<<0<<"\n";
			continue;
		}
		else if(a1 == 0) {
			cout<<1<<"\n";
			continue;
		}
		ll p = 1, ans = 0;
		ll p0 = (a0 * pw(a0 + a1, md - 2))% md, p1 = (a1 * pw(a0 + a1, md - 2)) % md;
		x /= gcd(x, y);
		y /= gcd(x, y);
		auto calc = [&](auto self, ll x, ll y) -> void{
			//cout<<x<<" "<<y<<endl;
			if(x == 1){
				ans += (p * pw(p0, y))% md;
				ans %= md;
				return;
			}	
			else if(y == 1){
				ans += (p * ((1 + md - pw(p1, x)) % md))% md;
				ans %= md;
				return;
			}
			if(x > y){
				ll n = x / y;
				ans += (p * ((1 + md - pw(p1, n) % md)))% md;
				ans %= md;
				p *= pw(p1, n);
				p %= md;
				x = x % y;
				self(self, x, y);
			}
			else{
				ll n = y / x;
				p *= pw(p0, n);
				p %= md;
				y = y % x;
				self(self, x, y);
			}
		};
		calc(calc, x, y);
		cout<<ans<<"\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3568kb

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: 187ms
memory: 3636kb

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
840419223
138416357
923054458
45779380
870227707
138831071
86396463
418241317
46851356
951368934
98275033
618861008
750317399
922456360
486881524
824329239
198191519
469859318
853799961
512645443
436852567
703100783
766215280
438470182
246877045
39876086
162987378
405196653
80959...

result:

wrong answer 3rd lines differ - expected: '612621163', found: '840419223'