QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#397324#5272. Greatest Common DivisorzhouhuanyiRE 196ms18052kbC++141.0kb2024-04-23 22:49:242024-04-23 22:49:26

Judging History

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

  • [2024-04-23 22:49:26]
  • 评测
  • 测评结果:RE
  • 用时:196ms
  • 内存:18052kb
  • [2024-04-23 22:49:24]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 2000000
using namespace std;
long long read()
{
	char c=0;
	long long sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
int gcd(int x,int y)
{
	if (!y) return x;
	else return gcd(y,x%y);
}
int F(int x,int y)
{
	if (!y) return x;
	else return F(y,x/y);
}
struct reads
{
	int x,y;
	bool operator < (const reads &t)const
	{
		return x!=t.x?x<t.x:y<t.y;	
	}
};
reads tong[N+1];
int n,q,length;
int main()
{
	int d,l,r;
	long long x;
	n=read(),q=read();
	for (int i=2;i<=n;++i)
		for (int j=1;j<=n/i;++j)
			if (i%F(i,j)==0)
			{
				d=F(i,j),l=i*j,r=min(i*(j+1)-1,n),l=(l+d-1)/d*d,r=r/d*d;
				if (l<=r)
				{
					for (int k=l;k<=r;k+=d)
						if (gcd(k,i)==d)
							tong[++length]=(reads){k,i};
				}
			}
	sort(tong+1,tong+length+1);
	while (q--)
	{
		x=read();
		if (x<=length) printf("%d %d\n",tong[x].x,tong[x].y);
		else puts("-1 -1");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3836kb

input:

10 13
1
2
3
4
5
6
7
8
9
10
11
12
13

output:

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

result:

ok 26 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 3524kb

input:

1 1
1

output:

-1 -1

result:

ok 2 number(s): "-1 -1"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3776kb

input:

5 100
2
20
17
14
23
19
8
10
21
19
16
16
19
16
6
11
9
12
5
12
21
8
15
5
24
5
5
17
6
12
1
21
25
3
20
8
7
11
15
8
6
1
16
25
14
1
11
13
11
20
6
2
5
7
3
6
19
20
3
22
21
11
13
18
18
14
2
1
19
3
20
23
3
16
1
8
14
16
11
9
10
17
22
3
8
12
2
12
9
5
18
6
9
25
6
12
19
14
16
6

output:

3 3
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
5 5
-1 -1
-1 -1
-1 -1
-1 -1
5 5
-1 -1
5 5
5 5
-1 -1
-1 -1
-1 -1
2 2
-1 -1
-1 -1
4 2
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
2 2
-1 -1
-1 -1
-1 -1
2 2
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
3 3
5 5
-1 -...

result:

ok 200 numbers

Test #4:

score: 0
Accepted
time: 0ms
memory: 3832kb

input:

20 100
289
374
235
204
189
215
84
194
242
331
216
326
264
113
181
344
124
91
39
189
256
77
228
155
201
52
386
31
384
397
267
282
226
249
400
208
48
176
131
296
288
266
75
367
298
311
388
165
11
121
44
269
325
293
392
210
365
150
221
365
188
298
23
192
223
179
245
286
103
118
314
352
394
255
78
225
4...

output:

-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
10 4
-1 -1
-...

result:

ok 200 numbers

Test #5:

score: 0
Accepted
time: 1ms
memory: 3852kb

input:

100 10000
6612
4694
4970
8529
7165
1355
9979
3049
2281
9998
5330
6674
5280
7838
729
810
5836
1465
5805
5812
5933
9493
7134
2581
3173
9673
2322
2776
3053
1377
9601
1547
1902
93
3114
5408
7577
8994
8173
189
6672
3431
2832
4764
6650
6842
379
7307
1283
7753
6203
1229
1849
297
9026
6520
9568
4419
5093
81...

output:

-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
57 57
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
...

result:

ok 20000 numbers

Test #6:

score: 0
Accepted
time: 7ms
memory: 3876kb

input:

1000 200000
134451
18536
303685
537674
428477
446829
583452
904095
295077
864453
949776
744108
144837
500318
596486
214710
338668
667766
679253
603928
158044
947810
272203
572606
767501
295561
508775
629483
950313
206695
394144
959539
932878
230667
676892
318913
642959
274136
662458
834771
792627
36...

output:

-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
...

result:

ok 400000 numbers

Test #7:

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

input:

10000 200000
2655653
24587357
25148377
40766601
43392625
53598135
20747785
35410107
39405761
58571003
50359654
79351089
20229583
11737455
91700105
75175779
26082486
26421724
51374385
2587276
15213302
69282831
73995969
38365995
37916148
97717081
11920317
64165764
28306295
40932112
94352977
55672605
1...

output:

-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
...

result:

ok 400000 numbers

Test #8:

score: 0
Accepted
time: 196ms
memory: 18052kb

input:

100000 200000
9900160421
1838711025
7215006831
4873988367
736988586
8927878267
9133829796
7556948229
1897988856
5049034409
4778625059
5483590472
2534396502
9316515227
4739195532
5161682788
8724411871
3977298661
9241212439
3737115542
1478991748
4568993297
2152062989
9851759441
1147444104
8871096091
8...

output:

-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
...

result:

ok 400000 numbers

Test #9:

score: -100
Runtime Error

input:

200000 200000
32948377113
22059645181
23497311013
25253281510
39793515626
1865678358
9158656229
1778918552
13975436773
5477506324
21783129513
25651988491
34533469254
3463578976
37359343310
29676790297
14241253550
19999612518
36671331160
36450209763
14059416609
31447483418
24044362859
26764502859
273...

output:


result: