QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#53572#2306. 迷宫not_so_organic100 ✓180ms3688kbC++111.5kb2022-10-05 13:31:142022-10-05 13:31:17

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-05 13:31:17]
  • 评测
  • 测评结果:100
  • 用时:180ms
  • 内存:3688kb
  • [2022-10-05 13:31:14]
  • 提交

answer

#include <bits/stdc++.h>
#define N 3005
#define int long long
using namespace std;

template <typename T>

void read(T &a)
{
	T x = 0,f = 1;
	register char ch = getchar();
	while (ch < '0' || ch > '9')
	{
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	a = x * f;
}

template <typename T>

void write(T x)
{
	if (x < 0) putchar('-'),x = -x;
	if (x < 10) return (void) putchar(x + '0');
	write(x / 10);
	putchar(x % 10 + '0');
}

template <typename T>

void writeln(T x)
{
	write(x);
	putchar('\n');
}

template <typename T>

void writes(T x)
{
	write(x);
	putchar(' ');
}

template <typename T,typename... Args> 

void read(T &t,Args &... args)
{
	read(t);
	read(args...);
}

template <typename T,typename... Args>

void writes(T t,Args ... args)
{
	writes(t);
	writes(args...);
}

template <typename T,typename... Args>

void writeln(T t,Args ... args)
{
	writes(t);
	writes(args...);
	putchar('\n');
}

int gcd(int x,int y)
{
	if (!y) return x;
	else return gcd(y,x % y);
}

int clac(int n,int m,int k,int d)
{
	d = gcd(d,k);
	if (d == 1 || n <= k / d) return n;
	if ((long double) k / d / m <= (long double) (k - n) / d) return k / d;
	return clac(k / d - m / d * (k - n),m,k / d,d) + m / d * (k - n);
}

signed main()
{
	int t;
	read(t);
	while (t--)
	{
		int m,k;
		read(m,k);
		writeln(clac(k - 1,m,k,m) + 1);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 2ms
memory: 3560kb

input:

50
2 1
2 2
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
3 1
3 2
3 3
3 4
3 5
3 6
3 7
3 8
3 9
3 10
4 1
4 2
4 3
4 4
4 5
4 6
4 7
4 8
4 9
4 10
5 1
5 2
5 3
5 4
5 5
5 6
5 7
5 8
5 9
5 10
6 1
6 2
6 3
6 4
6 5
6 6
6 7
6 8
6 9
6 10

output:

1
2
3
3
5
4
7
4
9
6
1
2
2
4
5
3
7
8
3
10
1
2
3
2
5
4
7
3
9
6
1
2
3
4
2
6
7
8
9
3
1
2
2
3
5
2
7
5
4
6

result:

ok 50 lines

Test #2:

score: 10
Accepted
time: 0ms
memory: 3528kb

input:

100
6 42
11 42
10 48
10 90
6 48
4 96
5 42
27 80
18 54
15 36
10 63
21 60
10 45
6 66
4 50
16 63
14 70
5 52
18 49
3 75
27 54
5 50
6 49
12 35
18 78
21 40
15 45
16 84
9 60
5 33
8 84
9 35
5 80
5 33
6 75
12 36
24 84
16 50
15 70
7 77
12 36
8 63
5 30
3 40
30 70
5 35
8 36
20 30
16 45
6 48
4 50
6 30
18 52
8 88...

output:

8
42
18
10
6
6
42
80
3
10
63
21
10
12
26
63
6
52
49
26
3
4
49
35
14
40
3
22
21
33
22
35
17
33
26
3
8
26
15
12
3
63
7
40
8
8
10
4
45
6
26
6
23
12
44
19
26
10
3
10
26
55
7
5
23
35
4
8
14
55
2
38
33
2
8
65
77
1
3
23
6
41
3
9
6
18
6
4
9
2
18
1
18
49
59
3
12
58
4
7

result:

ok 100 lines

Test #3:

score: 10
Accepted
time: 2ms
memory: 3516kb

input:

100
10 54
5 75
36 55
11 42
8 63
15 65
9 50
6 66
8 72
20 30
18 48
10 50
24 54
10 42
15 60
10 49
7 54
12 42
18 75
9 54
6 45
13 52
6 54
14 42
10 72
10 45
20 39
12 72
36 66
14 36
18 45
20 90
21 63
6 72
12 30
14 36
8 40
24 54
5 30
10 42
7 30
6 50
9 44
5 98
14 50
6 52
12 75
6 54
6 63
4 66
12 60
10 72
12 4...

output:

28
5
55
42
63
14
50
12
10
4
8
3
8
22
5
49
54
8
26
4
8
5
5
4
24
10
39
3
12
17
6
10
3
4
6
17
6
8
7
22
30
26
44
98
26
17
26
5
10
34
6
24
12
14
10
16
3
8
36
55
7
3
10
33
3
22
14
10
22
3
2
52
3
7
25
5
2
2
23
82
10
45
8
5
6
4
90
2
7
49
2
4
44
7
1
16
5
68
28
13

result:

ok 100 lines

Test #4:

score: 10
Accepted
time: 2ms
memory: 3508kb

input:

100
96 32768
1584 40950
240 61250
196 68607
350 56700
800 64680
1024 65536
704 60480
882 41160
224 79380
784 53900
2106 52488
180 53235
910 56133
396 79200
99 30030
30 61740
240 39690
1470 58800
80 55125
280 75600
378 63000
1680 68600
49 77440
64 65536
6 62208
39 33000
42 49000
65 81081
28 31500
151...

output:

14
2276
1250
9802
83
1618
3
946
14
414
276
16
1184
8020
52
911
345
450
6
714
29
254
14
77440
4
10
11001
138
6238
1126
144
2001
5
150
4
72
83
2179
3
224
51
177
56628
135
82
278
1126
141
13553
4005
45
5
56
73
98
51
15
22
7
288
44
11
8
3
4
21
76
60
4
18
25807
11302
18132
44697
1492
48743
5417
71364
841...

result:

ok 100 lines

Test #5:

score: 10
Accepted
time: 2ms
memory: 3580kb

input:

100
132 74250
512 90112
312 34398
630 90552
2142 87360
88 73710
280 74088
375 42336
896 90112
280 73500
117 55055
99 19305
60 68040
1716 61710
120 7436
864 56700
528 35100
1260 8100
182 56056
432 17640
728 6875
384 93312
625 74480
350 75600
2275 61740
336 89100
336 11664
300 13728
360 70070
648 6240...

output:

216
13
152
170
1092
36856
195
4830
19
18
4236
67
75
112
1860
184
1020
9
24
246
6875
83
14897
110
318
2504
89
312
7008
353
24
20826
5
716
14978
4236
22
1184
270
3
127
2777
60500
51
2724
29
35
59
7
113
96
17
19
260
27
12
30
90
23
4
31
17
54
58
28
7
8
20
7
12
540
2234
37965
353
16136
454
43941
41726
33...

result:

ok 100 lines

Test #6:

score: 10
Accepted
time: 2ms
memory: 3524kb

input:

1000
5 591470975
7 847425747
7 128685172
7 426595274
11 148547586
11 284777977
11 345556882
2 961544192
3 956593800
5 195312500
2 422576128
11 4787607
11 214358881
5 191806250
11 990746394
2 917063888
11 245441724
2 891132928
5 172187500
11 876922695
2 212076544
11 921211720
7 341359774
3 838828224
...

output:

23658841
13
2626230
82
10150
2353539
23606
937
214
15
423
331
9
61383
90067855
57316497
1529
870257
2211
52
103564
526
142178
383559
170933
454
29
326077
10391
3376
305
1732558
356448
196
120
11
45
4874
7321627
159
12
34158
18
66523176
70266
297
1212201
17
11
7769114
11124
235
4275
505
124893
486115...

result:

ok 1000 lines

Test #7:

score: 10
Accepted
time: 1ms
memory: 3568kb

input:

1000
360 540000000
162 483729408
60 211680000
320 503316480
648 153055008
144 286654464
840 600112800
45 789750000
91 919444500
81 108045000
720 171500000
896 939524096
200 256132800
384 201326592
6 647446800
117 32792760
1470 226203120
150 119070000
1050 842751000
420 62233920
300 50218630
162 5248...

output:

184
524
53
38
13
6
85
484
418557
12005001
43533
59
160085
15
13488489
21562
640397
175
98
28
5021864
584
1803
2408
31
733
44
2407
105
88
13739
303
44
890773
709
741139
69
260109
65908
58871
34799
1165
4567589
1869942
1588
448003
192
8261
2760616
48127
13921
212521
20565
1289
457733
4544751
86233
510...

result:

ok 1000 lines

Test #8:

score: 10
Accepted
time: 3ms
memory: 3556kb

input:

1000
72 60466176
264 763062300
84 101501400
660 673076250
78 543943400
900 870882012
84 667012500
24 300056400
288 453496320
192 612220032
1485 633368736
125 744323580
100 899640000
72 429981696
686 498279600
245 141711570
154 219008790
600 754515000
22 619699080
144 45349632
216 644972544
65 371599...

output:

9
15944
604177
5776
402338
24191168
378127
27301
203
61131
6397665
148864717
22494
7
8914707
4048903
129287
3473
640188
46
12
2198818
315526
231
1565
39
46626
142813
2095
30
396
94314
12
29665
558
38082
81078
3996
121123
413345
5934
74030113
15
214377
38300
107165
134
501
2323294
8621993
1366877
15
...

result:

ok 1000 lines

Test #9:

score: 10
Accepted
time: 180ms
memory: 3688kb

input:

300000
26 342351597906687600
16 680190786135918750
12 495748515330178110
12 321911943978757440
24 300573175060758600
10 339320798039331360
40 97155579561276600
2 913627974728736960
24 508577218808754375
26 315925421046785550
8 958372624367730000
60 885161360264643000
50 967237093434375000
4 60864707...

output:

21396974869170355
340095393067959376
1020058673519056
1676624708222700
4174627431399427
2120754987745978
485777897806385
14275437105136521
232545596462718
5530713578783
59898289022983127
98351262251631
309515869903
4755055244137279
1128544302221881
1127068705812098
607258146075297
989800092956681
45...

result:

ok 300000 lines

Test #10:

score: 10
Accepted
time: 154ms
memory: 3524kb

input:

300000
36 95729203815535290
18 72946720038956400
10 200049407499392640
20 32169429450873000
35 265271386712850000
35 382649386656665700
98 894521509672218750
36 183519691058287584
50 458076723717579120
25 361936023116400000
5 83871475379697600
10 244680644492640000
18 625069140750826200
64 606784890...

output:

15954867302589216
18762016470931
312577199221708
32169429450877
1732384566347
15305975466266636
1303967215265627
7866927771706
5725959046472995
115819527397251
3354859015187906
1529254028239
8681515843761486
18083598918
1495712184
58913125748050
667076837760738
3753661274138
85891987350815626
142054...

result:

ok 300000 lines

Extra Test:

score: 0
Extra Test Passed