QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#94602#6266. Good BitstringsQingyu100 ✓2ms3480kbC++231007b2023-04-06 21:00:182023-04-06 21:00:23

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-06 21:00:23]
  • 评测
  • 测评结果:100
  • 用时:2ms
  • 内存:3480kb
  • [2023-04-06 21:00:18]
  • 提交

answer

#include <bits/stdc++.h>

#define forp(_i) for (int _i = 0; _i < 6; ++_i)
using namespace std;

string gen_string(int64_t a, int64_t b) {
	string res;
	int ia = 0, ib = 0;
	while (ia + ib < a + b) {
		if ((__int128)ia * b <= (__int128)ib * a) {
			res += '0';
			ia++;
		} else {
			res += '1';
			ib++;
		}
	}
	return res;
}

int64_t solve(int64_t a, int64_t b) {
	if (a == b)
		return 2 * a - 1;
	if (a - b > b) {
		int64_t k = (a - b) / b;
		return k + solve(a - k * b, b);
	}
	if (a < b) {
		int64_t k = b / a;
		if (b % a == 0) --k;
		return k + solve(a, b - a * k);
	}
	return (2 * a - b - 1) / (a - b) - 1 + solve(a - b, b);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
/*	set<string> ss;
	for (int a = 1; a <= 100; ++a) {
		for (int b = 1; b <= 100; ++b) {
			ss.emplace(gen_string(a, b));
		}
	}*/

	int T;
	cin >> T;
	while (T--) {
		int64_t a, b;
		cin >> a >> b;
		cout << solve(a, b) << '\n';
	}

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 4.7619
Accepted
time: 1ms
memory: 3460kb

input:

6
1 1
3 5
4 7
8 20
4 10
27 21

output:

1
5
7
10
6
13

result:

ok 6 lines

Test #2:

score: 4.7619
Accepted
time: 2ms
memory: 3432kb

input:

10
85 13
71 66
28 66
29 71
96 63
38 31
17 68
36 58
36 4
63 33

output:

20
32
12
15
27
16
36
12
15
17

result:

ok 10 lines

Test #3:

score: 4.7619
Accepted
time: 0ms
memory: 3380kb

input:

10
906 527
608 244
263 174
839 281
153 492
987 849
701 390
195 518
410 59
48 971

output:

23
42
50
80
19
31
28
32
30
34

result:

ok 10 lines

Test #4:

score: 4.7619
Accepted
time: 2ms
memory: 3348kb

input:

10
147825 752503
960741 512108
83790 812992
328545 187606
182751 847169
818963 814953
706940 588194
981994 867047
248103 887086
501412 307158

output:

88
68
62
156
76
446
98
58
68
80

result:

ok 10 lines

Test #5:

score: 4.7619
Accepted
time: 2ms
memory: 3404kb

input:

10
681404 333428
181650 647050
229028 687782
657455 275098
58398 718183
365468 24732
503720 479173
556360 20233
694125 203877
617154 619370

output:

95
141
363
54
148
60
88
232
85
564

result:

ok 10 lines

Test #6:

score: 4.7619
Accepted
time: 2ms
memory: 3464kb

input:

10
404235 140228
733083 982834
604701 282642
318592 567367
846008 887551
189157 486078
378169 480062
408938 400339
571460 63131
310407 774407

output:

126
76
73
49
88
58
60
129
178
127

result:

ok 10 lines

Test #7:

score: 4.7619
Accepted
time: 2ms
memory: 3352kb

input:

10
405251 463150
549854 432108
808582 443624
49509 52183
361422 938598
776469 624844
644904 51183
797412 713474
254877 321065
407957 46299

output:

1403
108
66
68
84
68
1172
21006
46
68

result:

ok 10 lines

Test #8:

score: 4.7619
Accepted
time: 0ms
memory: 3468kb

input:

10
663353776591300896 752020665300205866
943526717545269366 300114424946521359
230713640398918611 187010130850175053
118239107794585724 200822570858719651
723715408292350264 396254911812807997
704994781514794709 819815153424097044
296759919488427246 945994708325740034
927030050569777885 705328510163...

output:

576
314
1682
287
480
899
322
1005
664
627

result:

ok 10 lines

Test #9:

score: 4.7619
Accepted
time: 2ms
memory: 3352kb

input:

10
263959270418486736 511944810471618212
719955631781742290 884235488590662642
911958183634412763 115875852572241461
882870749898577341 896059443335458468
497522514232414628 118311430658869194
953631769711592758 442130823895113645
516877924612139121 25792863217482507
670853595357487791 2210828766491...

output:

503
186
463
679
327
331
229
269
269
1664

result:

ok 10 lines

Test #10:

score: 4.7619
Accepted
time: 2ms
memory: 3392kb

input:

10
213394634718308650 567314195893526830
118718333481546670 984222666619725683
521169680133050475 379632545405725706
529433210710147101 666030768028277123
248727345489185865 923284915041497532
555027965912713377 803887041840034130
349121089908475057 822348686848065296
607629682756169018 642020332228...

output:

276
244
207
472
1104
333
1074
288
590
1498

result:

ok 10 lines

Test #11:

score: 4.7619
Accepted
time: 2ms
memory: 3400kb

input:

10
975925299289124420 60303066417239296
766474983477708842 896147119677109501
37292938145223081 40635895974758701
202932421403534375 409995075828727680
269767950521665045 612979965315330039
648872061480630731 203238724068557061
515872085687282128 932457502235646100
752197651492851645 591490401816131...

output:

575
184
543
488
2313
283
302
974
264
322

result:

ok 10 lines

Test #12:

score: 4.7619
Accepted
time: 1ms
memory: 3396kb

input:

10
834598416537042887 606025100334242999
320428844366792646 151368673495529221
842633031722285124 117239895104072930
625021458914788036 949669118025122161
486067279580042617 962611646795744707
819755947652456438 427518443947948205
34030594912010556 588251327521452796
272271618017091404 3833210869571...

output:

479
1770
279
264
257
236
315
242
267
2859

result:

ok 10 lines

Test #13:

score: 4.7619
Accepted
time: 2ms
memory: 3428kb

input:

10
397193281271954503 61672130855956143
314492482187282527 654066356498811443
860745630666775130 569333826127128192
476297769468002128 352294660078528480
517761936701389633 534752001708683063
674202688566846814 64972659840190297
585800934763526200 297942354678997984
106591030796636628 31162653946104...

output:

248
242
555
292
244
272
534
228
356
398

result:

ok 10 lines

Test #14:

score: 4.7619
Accepted
time: 1ms
memory: 3352kb

input:

10
208 565667425097819020
55 157321119038912352
316907676466271933 526
886500984850879616 22
299149363183826900 250
987113150500653689 61
159 670025876873085627
937166187092977629 764
874753340780245712 360
214921484777387769 800038093746969281

output:

2719554928354919
2860383982525694
602486076932104
40295499311403632
1196597452735411
16182182795092699
4213999225616910
1226657312948958
2429870391056278
885

result:

ok 10 lines

Test #15:

score: 4.7619
Accepted
time: 1ms
memory: 3480kb

input:

10
166972379813397449 29
569066341265273971 539
506 968039217663997486
352182654566540336 969
121125523365707181 848
517719135958060282 793
738 784126291767169684
298484835440867551 651
603 365907938824348123
910247730461828965 805051032603503065

output:

5757668269427513
1055781709212057
1913120983525707
363449591915970
142836702082232
652861457702537
1062501750362040
458502051368495
606812502196291
1467

result:

ok 10 lines

Test #16:

score: 4.7619
Accepted
time: 2ms
memory: 3376kb

input:

10
553486341350597216 428
126 131864838709694768
488211818967176514 885
830 514390130212884291
548964274098890426 286
621370290006585458 204
257458383843435158 856
758 307692053217471135
439 434604040461145810
943589164042917917 667787609709087533

output:

1293192386333213
1046546338965896
551651772844308
619747144834823
1919455503842295
3045932794149964
300769140004081
405926191579807
989986424740685
230

result:

ok 10 lines

Test #17:

score: 4.7619
Accepted
time: 2ms
memory: 3392kb

input:

10
320654112354370136 755
681 573231478158788514
375 855899714394872507
424 703958346499687295
143 455080993131748359
696 741114359393839020
332216328717809233 828
865773491535017948 263
480 875075196649813697
856882629296459076 668553697725070634

output:

424707433582256
841749600820568
2282399238386346
1660279119103072
3182384567354903
1064819481887741
401227450142320
3291914416483008
1823073326353802
280

result:

ok 10 lines

Test #18:

score: 4.7619
Accepted
time: 1ms
memory: 3424kb

input:

10
450591848507395078 766
970498285745258150 887
867038654838117493 714
443 698101902806352737
387 449758430496187790
928952692836028738 882
378854113906172456 822
74 220142603208608569
442341090408329812 239
44892686468418987 155998982976513680

output:

588240011106301
1094135609633944
1214339852714501
1575850796402627
1162166487070309
1053234345619137
460893082610948
2974900043359591
1850799541457469
282

result:

ok 10 lines

Test #19:

score: 4.7619
Accepted
time: 0ms
memory: 3460kb

input:

10
531086304104565770 690
831665374188973520 355
247416398730469667 416
353278152789250259 494
679360140254826434 522
398 867668761409290914
747 460442302649347038
428 430798781926999813
660522762702293186 303
570848109939810343 23362523897201984

output:

769690295803806
2342719363912625
594750958486742
715137961111873
1301456207384766
2180072264847484
616388624697949
1006539210109851
2179943111228709
233

result:

ok 10 lines

Test #20:

score: 4.7619
Accepted
time: 1ms
memory: 3480kb

input:

10
686 681341882408235553
961632287055210199 674
908 102741991216141808
890 138144729944759257
419 829534498941150031
505 624489596307607256
871 609803422000753610
983533393633626409 998
212341556536790997 446
826239058008214318 864102713930342835

output:

993209741119930
1426754135096851
113151972705234
155218797690766
1979795940193742
1236613061995292
700118739380921
985504402438531
476102144701390
9639

result:

ok 10 lines

Test #21:

score: 4.7619
Accepted
time: 0ms
memory: 3340kb

input:

10
976965156031061996 243
843847568805985436 621
573992055384105067 876
586 308437172337246069
448791804432291466 662
34 217523497482835562
619081882696846159 150
175189397944495946 977
654 836460039817622971
654824899345401176 269167483489754436

output:

4020432740868597
1358852767803554
655242072356317
526343297503916
677933239323732
6397749925965766
4127212551312329
179313610997766
1278990886571336
415

result:

ok 10 lines