QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#307511#8017. 计算HJY202215 24ms3648kbC++14903b2024-01-18 19:05:562024-01-18 19:05:57

Judging History

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

  • [2024-01-18 19:05:57]
  • 评测
  • 测评结果:15
  • 用时:24ms
  • 内存:3648kb
  • [2024-01-18 19:05:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD = 998244353;
const ll INF = 2e18;
ll gcd(ll x,ll y){return y == 0 ? x : gcd(y,x % y);}
ll ksm(ll x,ll b,ll p = MOD){ll ret = 1;while(b){if(b & 1)ret = ret * x % p;x = x * x % p;b >>= 1;}return ret;}
int main(){
	//freopen("calculate.in","r",stdin);
	//freopen("calculate.out","w",stdout);
	int T;
	cin >> T;
	while(T--){
		ll m,a,b,c,d;
		cin >> m >> a >> b >> c >> d;
		ll L = ksm(m,gcd(a,b),INF) + 1,R = ksm(m,gcd(c,d),INF);
		if(a == 0 || b == 0)L = 1;
		if(c == 0 || d == 0)R = 0;
		ll len = R - L + 1;
		//cerr << L << ' ' << R << '\n';
		//cerr << "len = " << len << '\n';
		if(m & 1)cout << ((m - 1) * ksm(2,len / m) % MOD + ksm(2,len)) % MOD * ksm(m,MOD - 2) % MOD << '\n';
		else cout << ksm(2,len) % MOD * ksm(m,MOD - 2) % MOD << '\n';
	}
	return 0;
}
// (m - 1) 2 ^ (n / m) + 2 ^ n / m 

详细

Test #1:

score: 5
Accepted
time: 0ms
memory: 3580kb

input:

1
2 0 0 1 1

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Wrong Answer
time: 11ms
memory: 3580kb

input:

10000
9026580 948 269 622 88
9346507 381 242 826 606
9266080 948 589 28 666
8566088 808 523 402 338
9832014 278 123 146 1000
8000150 613 878 146 740
8296526 404 147 608 398
9062880 494 203 336 382
9375271 823 736 54 676
8465119 505 414 874 772
9535971 784 983 426 802
8258325 817 977 172 862
9656017 ...

output:

905681792
36583482
892988611
445688430
688429224
245790415
187520887
515539094
381471844
271161777
34131254
304989342
461098890
663268729
207847665
940079004
455282630
348149133
208257201
65508055
502154961
967981245
715019780
179961669
665233352
225679953
506745989
345467903
399991037
112394094
155...

result:

wrong answer 1st numbers differ - expected: '731703617', found: '905681792'

Test #3:

score: 0
Wrong Answer
time: 20ms
memory: 3504kb

input:

10000
9060194 192 71 24 178
8861291 135 338 24 794
8800613 173 760 704 362
9878509 367 418 58 964
8183946 856 951 406 316
8087229 458 105 770 342
8269502 205 147 614 334
8877019 851 143 206 10
9044859 710 949 210 584
8887395 571 856 550 428
8208494 383 628 74 646
9949585 697 450 794 738
9938335 224 ...

output:

222119240
647570858
309319566
883401245
763363386
852463469
146056549
678057940
63764626
303372342
719831805
871275480
821932292
652989871
822734701
899057561
343574195
295946456
953076263
586567496
327950760
438232119
342834050
598575061
108825202
45736636
406978150
359702783
175237171
383658536
72...

result:

wrong answer 1st numbers differ - expected: '255347738', found: '222119240'

Test #4:

score: 0
Wrong Answer
time: 24ms
memory: 3532kb

input:

10000
9110615 854 153 494 298
9386442 749 922 386 696
9270958 160 53 630 562
9643022 573 997 226 836
9824638 357 16 34 332
9962202 439 312 40 854
8974913 815 436 710 876
9362731 411 272 998 760
9814831 220 961 962 274
9310979 19 890 782 588
9425378 897 14 212 870
9572172 430 419 334 166
9101141 565 ...

output:

332948987
447063909
329361447
948460733
465503609
629443399
313591644
85350948
972654736
297494146
72291333
448101012
680813324
942407729
235278595
965474921
628480434
11708381
350041916
538598035
795259277
414791448
67905671
370025208
222103379
944268190
577541527
142899855
771272521
273177688
2673...

result:

wrong answer 1st numbers differ - expected: '556751174', found: '332948987'

Test #5:

score: 5
Accepted
time: 0ms
memory: 3644kb

input:

4
3 4 5 6 1
2 6 1 8 10
4 1 4 2 2
5 0 10 2 10

output:

1
2
1024
6710912

result:

ok 4 number(s): "1 2 1024 6710912"

Test #6:

score: 0
Wrong Answer
time: 0ms
memory: 3576kb

input:

5
18 10 9 4 6
14 7 4 4 6
18 6 5 8 2
12 5 2 4 10
11 5 6 2 6

output:

988362570
173959500
988362570
66665301
296665006

result:

wrong answer 1st numbers differ - expected: '8581218', found: '988362570'

Test #7:

score: 0
Wrong Answer
time: 0ms
memory: 3504kb

input:

5
11 9 5 3 3
12 8 9 9 6
10 10 7 3 9
10 5 4 3 6
6 9 6 4 8

output:

336307822
800590772
8873385
8873385
766213077

result:

wrong answer 2nd numbers differ - expected: '997249957', found: '800590772'

Test #8:

score: 0
Wrong Answer
time: 0ms
memory: 3636kb

input:

5
4 5 6 5 10
12 8 5 9 3
10 4 9 9 3
10 5 6 6 3
6 5 7 4 8

output:

336848941
800590772
8873385
8873385
461939854

result:

wrong answer 2nd numbers differ - expected: '997249957', found: '800590772'

Test #9:

score: 0
Wrong Answer
time: 0ms
memory: 3532kb

input:

5
11 80 29 27 84
11 31 27 87 6
4 46 54 95 80
6 45 62 88 92
12 70 34 3 75

output:

336307822
336307822
488237375
461939854
152844270

result:

wrong answer 4th numbers differ - expected: '811628181', found: '461939854'

Test #10:

score: 0
Wrong Answer
time: 0ms
memory: 3636kb

input:

5
58 91 37 75 5
62 99 67 10 75
55 51 92 70 85
55 86 16 50 85
29 54 95 36 78

output:

982860430
515971704
361711626
155658006
460843296

result:

wrong answer 1st numbers differ - expected: '413751362', found: '982860430'

Test #11:

score: 0
Wrong Answer
time: 0ms
memory: 3556kb

input:

5
10 57 94 99 18
19 97 77 63 98
62 44 4 90 35
61 3 54 25 60
62 57 65 95 70

output:

935254803
961491285
678366528
755475251
515971704

result:

wrong answer 1st numbers differ - expected: '329246322', found: '935254803'

Test #12:

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

input:

5
5 0 0 9 5
4 0 0 1 5
2 0 0 7 5
3 0 0 3 7
3 0 0 9 5

output:

8
4
2
4
4

result:

ok 5 number(s): "8 4 2 4 4"

Test #13:

score: 0
Wrong Answer
time: 0ms
memory: 3576kb

input:

5
1931 633 387 65 265
1334 942 887 115 455
1547 511 57 65 920
1815 983 313 575 430
1497 749 773 25 740

output:

825344814
925569567
344141142
508675697
571040005

result:

wrong answer 2nd numbers differ - expected: '187842409', found: '925569567'

Test #14:

score: 0
Wrong Answer
time: 0ms
memory: 3580kb

input:

5
1676 347 892 10 545
1552 901 243 595 705
1585 181 32 900 215
1043 147 153 250 195
1343 519 863 610 345

output:

394998588
400924401
442918303
824055616
43767979

result:

wrong answer 1st numbers differ - expected: '733422553', found: '394998588'

Test #15:

score: 0
Wrong Answer
time: 0ms
memory: 3640kb

input:

5
1507 98 480 995 565
1130 476 464 710 925
1556 518 459 65 445
1153 277 530 485 860
1329 191 777 315 905

output:

112168975
950820789
194144309
293028836
584054355

result:

wrong answer 1st numbers differ - expected: '919146531', found: '112168975'

Test #16:

score: 0
Wrong Answer
time: 0ms
memory: 3644kb

input:

5
1260 985 161 855 395
1919 286 557 10 155
1439 586 749 915 730
1297 750 832 245 855
1693 134 289 355 200

output:

778316438
182309548
141714492
897734272
587745788

result:

wrong answer 1st numbers differ - expected: '396457042', found: '778316438'

Test #17:

score: 0
Wrong Answer
time: 0ms
memory: 3568kb

input:

5
95803 976 729 633 237
99669 606 7 489 816
80026 339 914 753 933
97238 844 430 666 537
70169 394 204 411 738

output:

263714877
704782044
792734720
553781255
929966786

result:

wrong answer 2nd numbers differ - expected: '43312442', found: '704782044'

Test #18:

score: 0
Wrong Answer
time: 0ms
memory: 3636kb

input:

5
86711 965 851 300 273
97658 466 416 633 603
89583 407 591 411 3
84126 987 514 822 837
79996 9 166 807 15

output:

625186250
764830555
995280637
353966387
831503255

result:

wrong answer 2nd numbers differ - expected: '867386840', found: '764830555'

Test #19:

score: 0
Wrong Answer
time: 0ms
memory: 3580kb

input:

5
90325 2 48 195 528
83446 123 809 897 60
92466 526 768 441 447
95582 319 251 843 447
95424 374 218 162 597

output:

509042349
354089191
100169539
530032480
374050922

result:

wrong answer 1st numbers differ - expected: '962318822', found: '509042349'

Test #20:

score: 0
Wrong Answer
time: 0ms
memory: 3632kb

input:

5
80746 952 565 615 192
71949 878 950 357 789
99398 301 646 942 699
94853 670 947 141 276
82409 554 873 375 213

output:

679172544
755864049
212168619
701414115
532022399

result:

wrong answer 1st numbers differ - expected: '896071730', found: '679172544'