QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#585463#9376. GameckboxWA 132ms3844kbC++141.6kb2024-09-23 20:54:072024-09-23 20:54:07

Judging History

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

  • [2024-09-23 20:54:07]
  • 评测
  • 测评结果:WA
  • 用时:132ms
  • 内存:3844kb
  • [2024-09-23 20:54:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;

struct fraq{
	ll fz,fm;
};

ll qpow(ll x, ll y){
	x = (x % MOD + MOD ) % MOD;
	ll ans = 1;
	while(y){
		if(y & 1)ans = ans * x % MOD;	
		x = x * x % MOD;
		y >>= 1;
	}
	return ans;
}

fraq operator+(const fraq& a,const fraq& b){
	ll fz =(a.fz * b.fm % MOD + MOD) % MOD + (a.fm * b.fz % MOD + MOD) % MOD;
	fz %= MOD;
	ll fm = (a.fm * b.fm % MOD + MOD ) % MOD;
	return {fz,fm}; 
}

fraq operator*(const fraq& a,const fraq& b){
	return {(a.fz * b.fz % MOD + MOD ) % MOD,(a.fm * b.fm % MOD + MOD ) % MOD};
}

fraq qpow(const fraq& a,ll y){
	return {qpow(a.fz,y),qpow(a.fm,y)};
}

fraq operator-(const fraq &a){
	return {-a.fz,a.fm};
}

fraq operator-(const fraq &a,const fraq &b){
	return a + (-b);
}

ll value_mod(const fraq& a){
	return a.fz * qpow(a.fm,MOD - 2) % MOD;
}

void solve(){
	ll x,y;
	ll a0,a1,b;
	cin >> x >> y >> a0 >> a1 >> b;
	fraq p0 = {a0,a0+a1},p1 = {a1,a0+a1};
	
	function<fraq(ll,ll)> work = [&](ll x,ll y) -> fraq{
		//cerr << x << ' ' << y << '\n';
		if(x == 0)return {0,1};
		if(y == 0)return {1,1};
		
		fraq ans;
		if(x < y){
			ans = work(x,y%x);
			ans = ans * qpow(p0,y / x);
		}else{
			ans = work(x%y,y);
			fraq z = fraq({1,1}) - p1;
			fraq q = fraq({1,1}) - qpow(p1,x / y);
			q = p0 * q;
			q = fraq({z.fm,z.fz}) * q;
			ans = q + ans;
		}
		
		return ans;
	};
	
	fraq ans = work(x,y);
	cout << value_mod(ans) << '\n';
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t;
	cin >> t;
	while(t--) solve();
	return 0;
} 

詳細信息

Test #1:

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

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: 63ms
memory: 3844kb

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: 132ms
memory: 3776kb

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:

270066146
158563996
500944054
551932321
103101818
931745086
689289605
19533924
825583108
27658649
108626964
505409338
630836520
654221996
809676747
147420095
859124342
858162985
410762032
486127423
770630570
738910405
507330965
418746922
840043216
290720809
503111544
809583496
298144192
551635436
18...

result:

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