QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#583551#9376. GamehuangceWA 170ms3656kbC++171.4kb2024-09-22 20:32:222024-09-22 20:32:23

Judging History

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

  • [2024-09-22 20:32:23]
  • 评测
  • 测评结果:WA
  • 用时:170ms
  • 内存:3656kb
  • [2024-09-22 20:32:22]
  • 提交

answer

/*
 * @Author: dsaDadas11
 * @Date: 2024-06-27 10:33:26
 * @LastEditTime: 2024-09-22 20:31:54
 * @Description: go for it!
 */
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define int ll
using namespace std;
constexpr int N=1e6+7;
constexpr int M=2e3+7;
constexpr int mod=998244353;
int quickpow(int x,int y)
{
	int ans=1;
	while(y)
	{
		if(y&1) ans=(ans*x)%mod;
		x=(x*x)%mod;
		y>>=1;
	}
	return ans;
}
int niyuan(int x)
{
	return quickpow(x,mod-2);
}
int x,y;
int a0,a1,b,a;
int p0,p1;
int dfs(int x,int y)
{
	if(x>y)
	{
		int cnt1=x/y;
		int r=x%y; //x
		int tp=(p0*(1-quickpow(p1,cnt1))%mod)*niyuan(1-p1)%mod;
		if(r==0)
		{
			return tp;
		}
		return tp*dfs(r,y);
	}
	if(x<y)
	{
		int cnt=y/x;
		int tp=quickpow(p0,cnt);
		y-=cnt*x;
		if(y==0) return tp;
		return tp*dfs(x,y);
	}
	if(x==y)
	{
		return p0;
	}
	return 0;
}
void solve()
{
	cin>>x>>y;
	cin>>a0>>a1>>b;
	a=a0+a1;
	p0=a0*niyuan(a)%mod;
	p1=a1*niyuan(a)%mod;
	if(x==y)
	{
		cout<<p0<<endl;
		return;
	}
	int tp=1;
	if(x<y)
	{
		int cnt=y/x;
		tp=quickpow(p0,cnt);
		y-=cnt*x;
		if(y==0)
		{
			cout<<tp<<endl;
			return;
		}
	}
	// 现在 x>y了
	int ans=tp*dfs(x,y)%mod;
	cout<<ans<<endl;
}
signed main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int T=1; cin>>T;
	while(T--){solve();}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 54ms
memory: 3648kb

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
612621163
138416357
592200562
45779380
870227707
169499045
86396463
415694940
46851356
951368934
426243016
864656779
750317399
922456360
486881524
824329239
198191519
189360084
966510181
512645443
695650039
703100783
550002158
438470182
246877045
39876086
667870434
405196653
5935...

result:

ok 100000 lines

Test #3:

score: -100
Wrong Answer
time: 170ms
memory: 3656kb

input:

100000
167959139 481199252
18199423 25950409 149762920
773386884 579721198
16629525 28339910 152155823
2087506 268792718
43528658 6471925 90197530
691952768 717268783
516613092 94328992 743662288
45277106 856168102
309821265 346013425 963168258
279198849 527268921
30167950 166388455 577970339
140515...

output:

876024019
63996167
126193507
-689663338
966591834
238721994
-804647489
-123390140
-55193011
375437576
746755028
344463155
-174208814
-319764572
-519133620
-791433854
-432619453
152545007
-64981169
-225935320
267934423
-633830567
-86424711
871293126
0
970960700
-891620148
-506118647
111119999
-806038...

result:

wrong answer 1st lines differ - expected: '623291477', found: '876024019'