QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#334906#7409. Fraction ReductionKevin5307AC ✓64ms3712kbC++201.1kb2024-02-22 15:06:152024-02-22 15:06:15

Judging History

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

  • [2024-02-22 15:06:15]
  • 评测
  • 测评结果:AC
  • 用时:64ms
  • 内存:3712kb
  • [2024-02-22 15:06:15]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
const ll mod=1e9+7;
ll solve(ll a,ll b)
{
	if(!a) return 0;
	if(a<0)
	{
		ll x=(-a+b-1)/b;
		a+=x*b;
		return (solve(a,b)+x)%mod;
	}
	if(a>=b-a&&b>a)
	{
		ll x=a/(b-a);
		ll tmp=b-a;
		a-=x*tmp;
		b-=x*tmp;
		return (solve(a,b)+3*x)%mod;
	}
	return (solve(-b,a)+1)%mod;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		ll a,b;
		cin>>a>>b;
		cout<<solve(a,b)<<'\n';
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

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

input:

5
0 1
1 1
-1 2
-2 4
8 5

output:

0
2
4
4
10

result:

ok 5 tokens

Test #2:

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

input:

99681
-223 1
-223 2
-223 3
-223 4
-223 5
-223 6
-223 7
-223 8
-223 9
-223 10
-223 11
-223 12
-223 13
-223 14
-223 15
-223 16
-223 17
-223 18
-223 19
-223 20
-223 21
-223 22
-223 23
-223 24
-223 25
-223 26
-223 27
-223 28
-223 29
-223 30
-223 31
-223 32
-223 33
-223 34
-223 35
-223 36
-223 37
-223 38...

output:

223
115
81
61
52
53
40
37
34
34
34
30
37
31
27
31
39
25
23
34
23
34
25
27
26
26
34
37
26
26
28
40
34
27
23
28
115
22
27
29
22
25
27
52
32
23
23
20
26
21
23
34
31
34
61
61
24
21
29
34
23
25
33
28
37
25
34
23
31
28
34
40
61
223
45
32
22
42
20
21
66
23
27
22
23
24
30
38
136
24
26
21
30
24
34
28
25
25
8...

result:

ok 99681 tokens

Test #3:

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

input:

100000
-49 75
52 58
-67 21
47 18
61 9
-53 89
70 19
38 50
59 46
92 73
-93 67
55 73
8 41
62 62
72 38
75 17
30 76
-29 35
-54 10
-77 58
98 74
-19 27
-16 74
-21 25
-36 52
62 1
-56 77
40 92
67 27
-75 4
66 50
-33 19
-8 27
-73 94
29 76
12 7
26 41
-36 75
65 91
13 9
91 11
96 78
47 67
-20 35
-44 50
-20 26
88 9...

output:

19
31
22
18
31
22
23
17
27
22
19
29
28
2
31
24
26
15
13
29
41
16
21
18
15
185
10
15
46
24
29
13
16
22
17
13
20
18
10
16
33
15
19
11
17
13
24
278
53
17
22
12
19
47
21
6
16
44
16
10
21
256
21
22
7
29
20
23
22
26
18
39
19
21
23
39
33
28
7
19
6
25
15
15
33
16
82
37
13
14
14
25
22
11
14
32
15
21
19
12
33...

result:

ok 100000 tokens

Test #4:

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

input:

100000
936 703
836 852
435 561
670 525
-607 429
980 377
109 310
703 708
-206 385
-314 887
933 922
-23 69
393 382
-544 855
-48 727
42 961
269 563
68 83
466 837
675 504
-556 747
-132 226
675 782
-152 460
-700 133
43 335
-195 714
-975 510
105 83
697 897
315 914
-132 6
160 62
369 563
844 256
849 206
253...

output:

185
162
33
21
32
236
26
428
36
39
98
7
48
89
60
41
49
25
34
27
34
37
43
47
25
24
75
21
21
67
38
22
21
43
28
39
37
28
56
52
53
483
50
86
56
33
63
38
31
29
50
33
24
41
60
29
43
161
227
28
48
250
97
21
42
41
31
131
109
41
29
94
32
47
36
51
98
45
53
21
31
207
46
32
51
47
58
51
43
70
22
46
39
30
36
30
34...

result:

ok 100000 tokens

Test #5:

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

input:

100000
8656 5813
-7165 4211
4378 6445
1016 1184
-5083 7854
3107 6033
-5345 5324
-8955 3379
-523 8381
-9697 2935
-2354 9803
-4102 5089
-4040 5188
4889 9897
-8202 2477
-4994 509
-6663 8571
-9044 4093
-367 6440
-2341 3918
8311 9204
7336 7720
3206 6193
-7887 8488
-6245 406
-923 1295
4895 6606
-2951 1488...

output:

92
213
47
41
91
69
774
69
103
55
69
37
55
149
51
42
55
45
75
43
70
76
41
62
43
34
59
100
74
36
36
64
389
34
35
165
44
65
199
82
32
48
35
58
49
50
28
43
53
50
89
53
53
53
66
39
47
63
35
80
192
37
76
41
134
103
108
64
46
68
6948
77
71
42
86
46
42
34
71
107
92
58
127
77
130
82
60
78
52
53
51
52
53
82
5...

result:

ok 100000 tokens

Test #6:

score: 0
Accepted
time: 24ms
memory: 3632kb

input:

100000
93861 23894
-76367 86256
1897 56234
7070 65872
-13581 10174
-52317 90627
-36108 49287
11126 14991
-31712 64606
50643 21823
-2131 52833
88221 8003
-57213 5041
90265 78670
65115 74195
-26621 42743
-6227 78543
85698 74872
-91002 44436
50744 8978
50051 62354
-39998 74951
53499 39454
-42208 37439
...

output:

113
84
76
82
290
53
50
70
58
65
124
102
63
72
57
60
90
62
119
93
85
123
59
66
111
51
70
154
66
144
78
100
115
58
72
57
85
72
99
68
83
154
72
50
191
175
74
216
186
72
60
55
291
61
131
164
77
66
176
143
72
207
139
97
59
62
51
51
62
514
242
82
147
81
53
83
54
67
133
160
205
61
67
500
96
125
59
123
53
1...

result:

ok 100000 tokens

Test #7:

score: 0
Accepted
time: 27ms
memory: 3632kb

input:

100000
-328344 45607
-899105 36007
17400 458723
295044 273220
-177656 460772
969904 588897
192748 98036
-654955 995905
-97663 927471
245912 176699
-851092 21769
87087 255804
-435869 571014
-736334 267906
272456 330112
559373 902497
-633445 659685
-979978 891394
525072 238839
-880255 301151
473838 86...

output:

122
91
93
141
68
230
210
71
291
69
91
108
107
121
57
63
77
110
114
104
121
82
64
100
85
61
110
951
118
87
99
193
503
107
87
81
507
84
130
171
79
69
74
278
64
320
82
119
62
224
122
92
140
100
129
317
112
145
91
355
129
402
119
185
87
126
99
96
141
113
138
81
95
85
90
173
70
67
109
125
505
62
91
77
66...

result:

ok 100000 tokens

Test #8:

score: 0
Accepted
time: 30ms
memory: 3708kb

input:

100000
-7176004 2767531
-9369074 803297
-7915246 2508468
4227142 7344438
-7791051 6954112
-6007448 4254037
-55223 8182791
9395876 9028249
-5236927 2223525
-4880451 5915264
1423981 4828955
6196634 2796587
5807402 4447372
-49219 9861986
389108 1430529
-3674120 1129998
9676754 8535782
1694057 1156542
8...

output:

96
106
102
90
119
94
494
120
126
124
69
187
114
1127
105
190
104
111
174
1353
131
155
101
281
179
138
170
9610
166
167
146
142
104
157
130
211
75
123
108
70
145
145
107
165
109
369
131
208
160
435
220
608
79
187
191
89
132
223
121
80
128
71
90
96
313
133
698
130
1068
94
230
127
279
137
237
84
90
61
...

result:

ok 100000 tokens

Test #9:

score: 0
Accepted
time: 29ms
memory: 3628kb

input:

100000
-64094429 30583838
-18037616 47163160
-32963690 59345563
22317106 54038594
23098307 27145639
-31992114 20697624
93342272 89957258
95112878 10745293
2313211 22756865
61156578 27674696
-57947842 85099964
28184317 86666147
75883009 68032225
-46014281 26641837
-96936528 60251271
92694955 79309929...

output:

118
99
211
106
126
178
175
118
340
118
178
255
191
181
517
110
136
118
166
217
100
96
165
130
142
166
162
131
159
239
1646
317
114
239
97
326
142
142
512
254
316
99
85
90
1117
185
145
2394
96
158
117
240
1174
154
136
124
132
172
186
164
136
100
812
150
914
127
187
293
110
214
437
201
196
203
160
135...

result:

ok 100000 tokens

Test #10:

score: 0
Accepted
time: 35ms
memory: 3628kb

input:

100000
912999054 394324876
476826386 963472492
298175549 836089252
-993303541 803800859
636501086 966281637
474893090 675730820
436485856 498190641
-500921164 586010717
-409568030 365334322
-307533953 148243933
379046876 110026320
888178834 820210756
-309159723 419975037
346423471 834492497
-7218474...

output:

98
225
170
197
264
124
414
248
220
161
166
182
127
130
367
93
274
136
306
134
218
796
558
356
117
181
137
372
85
217
586
935
150
123
157
212
154
114
115
212
284
268
166
169
130
2855
315
163
103
171
165
176
195
144
127
136
295
135
268
298
91
1104
253
390
150
113
142
1193
377
158
102
361
378
135
140
1...

result:

ok 100000 tokens

Test #11:

score: 0
Accepted
time: 40ms
memory: 3624kb

input:

100000
-8597510462 3197777932
4147079085 7564432242
-4004897097 1516678579
-7440175313 4911738541
-8486546113 7665128606
-4214400578 6270211251
-810032026 2630202590
8493546529 1595833068
439934525 178023638
-9075880417 2479188566
7355918055 5345718205
-2624884993 7561653763
-8342459052 5250691103
9...

output:

119
146
422
477
360
575
253
487
170
122
154
173
292
278
147
1287
310
147
236
404
109
141
123
119
124
217
165
141
236
125
440
847
133
172
116
197
272
139
293
216
150
191
217
108
213
139
235
144
170
275
1153
192
495
133
152
262
254
180
589
166
270
233
2541
171
179
352
388
177
154
171
246
119
314
110
7...

result:

ok 100000 tokens

Test #12:

score: 0
Accepted
time: 38ms
memory: 3624kb

input:

100000
-36481884542 95395951066
-38278293108 37755384110
-47360866363 72316932279
59315598754 85192573301
-34091117852 22654124427
10140138043 18947599395
-52192941951 70587913103
48478505565 3366576560
70983121222 51785491099
-72794362907 77858450808
4166490988 62537967533
73494451769 98574513724
-...

output:

240
326
321
314
549
312
198
2161
450
184
420
169
315
152
279
138
343
271
210
349
101
173
464
237
320
287
268
543
347
658
17570
237
274
178
158
172
286
324
219
172
310
135
733
113
587
294
171
26207
1436
323
132
260
243
216
427
170
1176
172
298
239
231
283
438
208
442
334
241
230
1189
172
182
295
851
...

result:

ok 100000 tokens

Test #13:

score: 0
Accepted
time: 45ms
memory: 3616kb

input:

100000
-51991943594 864837071768
670675777551 835942074509
-265405211987 463013642086
-822049430564 124835712524
490857995507 197928392889
541744833030 291188454241
-42190574343 337682888303
48954495374 420637768372
306875271682 129513767068
537990775293 934172030626
-338255459608 646053503749
-4509...

output:

204
166
302
263
418
551
424
137
646
198
204
275
146
598
218
302
126
418
282
630
141
262
180
338
229
283
507
346
211
276
223
8857
392
191
222
158
250
406
774
168
1749
378
164
160
163
292
203
248
421
150
611
229
373
168
231
221
202
693
341
200
224
274
220
225
246
181
202
412
2327
1703
344
355
146
1243...

result:

ok 100000 tokens

Test #14:

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

input:

100000
-3252119184392 2240920105921
9818037671152 9096515985535
9904720609864 6549912487527
-9776880564499 7255731319854
-3661017707841 1736287315636
3724399734803 4296631221060
8813686173199 4747780268570
-7407376201792 3925324985637
5518876529954 8489824196365
-7587951758518 3200313491062
-8676529...

output:

312
302
731
366
212
284
346
170
244
256
301
201
316
461
613
314
347
238
315
317
471
185
383
194
271
833
1822
578
198
280
322
292
204
183
757
222
235
332
247
186
570
776
198
238
268
204
340
662
169
306
260
4103
337
214
292
206
228
381
363
286
258
299
286
291
543
1763
480
384
172
1965
175
189
168
418
...

result:

ok 100000 tokens

Test #15:

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

input:

100000
25963208848030 37049333269972
16900021268841 62577843342344
74013104081789 93912940852175
83386570212117 29258500549796
-88112373010489 50800721822536
36928864735400 72703108375837
-32693146673626 54459545289908
-92992266445886 70792248341412
95033474526015 84904046511517
-64126751906245 2891...

output:

191
266
3158
1571
190
293
993
404
246
206
387
250
480
387
402
181
350
290
229
306
386
283
232
374
333
202
298
205
500
201
392
747
246
219
216
194
1229
218
370
5409
391
230
440
575
350
287
199
487
177
443
1349
258
225
181
691
276
206
249
302
854
223
274
192
397
771
2492
424
500
246
474
216
356
396
19...

result:

ok 100000 tokens

Test #16:

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

input:

100000
-236801138654954 354872085724601
-386851809642143 555066841947964
929794644924738 475832668549884
-690563026082069 710778225235227
764780048142140 601322370989882
-925377557664474 460546706946587
827137184202304 218973974939015
593258888817493 313812018125426
-116299813681118 616855585893212
...

output:

1500
224
226
1055
358
2568
954
234
194
341
198
514
310
281
269
408
217
198
315
410
422
294
344
461
202
216
500
228
389
267
711
313
226
266
233
250
485
202
484
1191
710
411
265
665
6623
443
603
9155
215
458
285
237
378
323
537
299
674
383
326
411
425
215
347
334
162
213
414
229
323
433
199
256
1056
4...

result:

ok 100000 tokens

Test #17:

score: 0
Accepted
time: 56ms
memory: 3704kb

input:

100000
9197075314108823 728733406681480
-2357993481411106 9989525670943338
3615849503677485 6617864220121425
-5783153199732575 1754302982504637
1279622065995534 6511226126587398
7605047211048864 3244994536785807
-3390732798405728 5043378011351611
-804192764304817 2643498245085728
-9094659464033718 4...

output:

620
406
289
282
3654
335
527
717
361
313
392
308
1289
304
622
379
296
360
432
248
310
297
303
402
393
328
295
300
821
249
1438
411
372
147173
215
636
768
359
412
3035
305
220
354
407
224
271
340
598
651
312
291
546
279
275
305
1397
447
317
257
1225
208
398
213
459
486
420
313
266
2233
1004
293
351
2...

result:

ok 100000 tokens

Test #18:

score: 0
Accepted
time: 61ms
memory: 3704kb

input:

100000
49214446031355813 22657695909341972
74767624979931832 41212336411205187
12250094415339760 89175642870792544
94563816848536959 85684568909584391
-1194491047910495 16675101467125365
-11772449045226244 89673845674995603
90660169724909698 93220709220388660
7154366939856984 74286326933845147
-5357...

output:

1715
227
249
373
1382
632
521
465
330
1351
336
279
517
555
888
364
233
380
545
13410
907
644
805
477
236
345
466
233
696
823
713
498
2584
272
300
271
461
4369
521
392
622
523
370
444
251
2414
295
736
526
524
1487
314
1870
318
488
285
383
1616
392
809
267
5571
567
1466
426
7632
359
302
210
329
410
47...

result:

ok 100000 tokens

Test #19:

score: 0
Accepted
time: 64ms
memory: 3616kb

input:

100000
554681714344206120 952642468411220141
-470436962368434010 335563419348691346
-879663593149898494 638645900460132297
453678721972869782 452600728728598667
204588124605255522 236079560163294084
-509386774803896331 482513204878523629
-517134476661936721 368766950437883098
541663416631378995 5876...

output:

259
426
408
653
1018
333
1555
296
2621
498
521
1392
335
377
357
307
554
762
761
332
920
377
392
663
348
323
379
393
311
809
2115
472
1117
453
911
446
461
409
823
386
474
389
387
631
1576
467
2649
254
456
1239
4336
275
239
342
351
276
230
315
500
380
444
1172
419
299
338
569
421
285
290
281
306
220
4...

result:

ok 100000 tokens

Test #20:

score: 0
Accepted
time: 30ms
memory: 3624kb

input:

100000
-999999999999936630 9423
-999999999999939797 19637
-999999999999915924 42716
-999999999999959494 84660
-999999999999973008 27251
-999999999999970781 74236
-999999999999974722 10877
-999999999999975094 35193
-999999999999995847 21254
-999999999999951166 53528
-999999999999960309 51582
-9999999...

output:

314549853
275245799
431524557
953614620
900811059
553276142
114370007
741369143
966735802
811257753
607595726
35552680
289685351
414173668
160982616
631676925
949602356
532018124
371978273
685465403
420644630
675856573
828740613
68510853
426155256
466253779
254810561
596496806
550788621
718868145
32...

result:

ok 100000 tokens

Test #21:

score: 0
Accepted
time: 25ms
memory: 3708kb

input:

100000
-999999999999992444 50216
-999999999999956730 11296
-999999999999972997 67565
-999999999999956044 85340
-999999999999992934 35616
-999999999999922256 61019
-999999999999962094 39552
-999999999999967176 87923
-999999999999950999 40563
-999999999999982171 14714
-999999999999913006 22946
-999999...

output:

971503206
911561797
562317867
834462217
268446815
337944037
171344099
588173936
8727817
484232756
580188309
523547304
564147384
769414439
17892109
961155557
530398373
733001577
449481224
343793104
809137423
189107839
629347592
90208746
616721358
459570106
652303332
66517982
452669717
458111597
48974...

result:

ok 100000 tokens

Test #22:

score: 0
Accepted
time: 31ms
memory: 3708kb

input:

100000
999999999999912823 60785
999999999999927263 14111
999999999999977698 15065
999999999999925292 93815
999999999999983853 34775
999999999999922339 14588
999999999999931012 29235
999999999999981798 19255
999999999999995147 2710
999999999999906132 36756
999999999999980125 42895
999999999999919130 ...

output:

281138495
97725388
71291179
828481647
870711827
476761875
725808154
686263378
62361692
326885458
220748398
67229699
111363861
2595583
741651210
650797576
987161859
137065417
487159687
586073576
347622487
355486949
598067296
935531634
282471639
666828199
118212919
937266247
540690398
368564416
198954...

result:

ok 100000 tokens

Test #23:

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

input:

100000
999999999999981357 25770
999999999999945572 5771
999999999999920625 39914
999999999999988329 94495
999999999999923514 75844
999999999999970864 1372
999999999999903228 57910
999999999999930128 39282
999999999999915647 30531
999999999999975128 65238
999999999999903080 46962
999999999999987706 4...

output:

434575136
578582609
596908507
711297026
875521140
905976650
523899293
856346497
783433660
468270079
435607553
322201480
272023803
520711221
67751920
764017617
338139402
593806561
450183032
675527943
367353994
672477208
457049303
813039188
437736069
702180066
449382230
15856237
563985723
193463733
55...

result:

ok 100000 tokens

Test #24:

score: 0
Accepted
time: 31ms
memory: 3624kb

input:

100000
52317 999999999999913080
41227 999999999999945418
60383 999999999999982092
16416 999999999999972660
4797 999999999999918432
88805 999999999999917927
11330 999999999999932324
41772 999999999999970600
37304 999999999999932953
87390 999999999999945302
17406 999999999999953037
36730 9999999999999...

output:

245713764
948601726
952470131
178910859
621638543
627138284
252692106
480824724
776565610
956780256
453119701
700871308
537965386
209923293
837824572
486154366
253194204
530453762
671595552
171817040
809244023
185856636
166184482
272689436
170443558
391066609
450739126
462893022
490458845
94889235
2...

result:

ok 100000 tokens

Test #25:

score: 0
Accepted
time: 22ms
memory: 3712kb

input:

100000
20850 999999999999959111
24294 999999999999977940
78964 999999999999902719
79454 999999999999959284
84872 999999999999987902
37329 999999999999921443
72652 999999999999998255
90103 999999999999962461
33458 999999999999941302
80732 999999999999919709
5121 999999999999915832
53999 9999999999999...

output:

630359786
426648606
998695676
898670990
448781763
823515344
245898330
409520291
217855280
661955669
359110356
861330855
526602544
827211926
869166728
934869574
92959484
15112339
306562855
405760366
728244286
884802537
786554872
291543416
771957373
515009859
17693619
235173909
236647887
420074628
866...

result:

ok 100000 tokens

Test #26:

score: 0
Accepted
time: 27ms
memory: 3708kb

input:

100000
-67420 999999999999996016
-48116 999999999999952222
-88401 999999999999905401
-20239 999999999999901120
-96519 999999999999907120
-67307 999999999999946982
-63635 999999999999976677
-64863 999999999999906218
-73520 999999999999901737
-26075 999999999999961090
-24791 999999999999918670
-15970 ...

output:

181533718
322034330
267451788
666387028
962919317
886713186
867038639
329402025
222782976
731697093
656609300
221603123
578881051
479159796
856999757
340136336
718739745
568355328
379411341
562218386
78445041
355470494
529000057
249671201
848547931
814864306
60248511
963967260
208968615
54065630
565...

result:

ok 100000 tokens

Test #27:

score: 0
Accepted
time: 32ms
memory: 3652kb

input:

100000
-23232 999999999999955498
-29808 999999999999909089
-21125 999999999999985616
-68096 999999999999987745
-16444 999999999999976590
-94436 999999999999926150
-91419 999999999999942607
-81292 999999999999933320
-28672 999999999999910086
-32733 999999999999970739
-1835 999999999999946224
-23048 9...

output:

230501447
121678786
833325501
450819521
361894953
546052405
935188591
135439
695696316
627165351
372751999
136888316
431419205
401292183
1650382
708271311
856889063
51440358
46689746
195539462
576753187
104410950
530826887
547033280
946660186
199233663
820066671
640487844
462199431
775261822
5960372...

result:

ok 100000 tokens

Extra Test:

score: 0
Extra Test Passed