QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#585822#9376. Gamexadiye24WA 348ms3588kbC++141.0kb2024-09-23 22:16:132024-09-23 22:16:13

Judging History

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

  • [2024-09-23 22:16:13]
  • 评测
  • 测评结果:WA
  • 用时:348ms
  • 内存:3588kb
  • [2024-09-23 22:16:13]
  • 提交

answer

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

const ll MOD=998244353;

ll pow(ll x,ll b){
	ll ans=1;
	x%=MOD;
	while(b){
		if(b&1) ans=ans*x%MOD;
		x=x*x%MOD;
		b>>=1;
	}
	return ans%MOD;
}

ll Inv(ll x){
	return pow(x,MOD-2)%MOD;
}

void solve(){
	ll x,y;
	cin>>x>>y;
	ll pa,pb,pz,sa,sb;
	cin>>pa>>pb>>pz;
	ll sum=pa+pb;
	ll gca=__gcd(pa,sum),gcb=__gcd(pb,sum);
	pa/=gca,sa=sum/gca,pb/=gcb,sb=sum/gcb;
	ll ka=pa*Inv(sa)%MOD,kb=pb*Inv(sb)%MOD;
//	cout<<"ka="<<ka<<" kb="<<kb<<endl;
	function<ll(ll,ll)> cal=[&](ll a,ll b){
		if(a==0) return 0ll;
		if(b==0) return 1ll;
		if(a>=b){
			ll pk=a/b;
//			cout<<"a="<<a<<" b="<<b<<" pk="<<pk<<endl;
			return ka*(pow(kb,pk)-1)%MOD*Inv(kb-1)%MOD+pow(kb,pk)*cal(a-pk*b,b)%MOD;
		}else if(a<b){
			ll pk=b/a;
//			cout<<"a="<<a<<" b="<<b<<" pk="<<pk<<endl;
			return pow(ka,pk)*cal(a,b-pk*a)%MOD;
		}
	};
	cout<<cal(x,y)<<endl;
}


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

詳細信息

Test #1:

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

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: 217ms
memory: 3572kb

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: 348ms
memory: 3588kb

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:

623291477
1006539278
601180149
463883218
142231120
497599259
476659890
1153662165
443629949
455506204
904783575
385844451
808860628
149767602
1009075181
677371444
448503075
1704658006
597810956
1868671325
1358769137
345163088
257088594
375675323
6636182
872339516
51833722
1025067953
25949962
1080964...

result:

wrong answer 2nd lines differ - expected: '8294925', found: '1006539278'