UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#207349#3738. 神奇公式Allen123456hello10022ms1204kbC++11666b2024-07-28 18:08:462024-07-28 20:08:31

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL arr[200005];int pos=0;
void init(LL n){
    arr[++pos]=n;arr[++pos]=1;
    for (LL i=2;i*i<=n;++i){
        if (!(n%i)){arr[++pos]=i;arr[++pos]=(n/i);}
    }
    sort(arr+1,arr+1+pos);
    pos=unique(arr+1,arr+1+pos)-arr-1;
}
void work(){
    LL l,r;
    scanf("%lld%lld",&l,&r);
    int ans=upper_bound(arr+1,arr+1+pos,r)-arr-1;
    if (arr[ans]<l){puts("-1");return;}
    printf("%lld\n",arr[ans]);
}
int main(){
    arr[0]=INT_MIN;
    LL x,y;int T;
    scanf("%lld%lld",&x,&y);
    init(__gcd(x,y));
    scanf("%d",&T);
    ++T;while (--T){work();}
    return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

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

input:

348416640 134006400
9203
381 904
396 976
54 147
360 788
62 154
500 1000
33 703
223 851
267 972
294 7...

output:

891
960
144
752
144
990
660
846
960
752
220
891
891
891
594
396
891
960
752
540
752
960
640
594
810
...

result:

ok 9203 numbers

Test #2:

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

input:

368398800 319278960
9318
259 853
150 428
426 984
65 257
293 967
304 859
99 928
189 730
493 990
278 7...

output:

840
420
924
252
924
840
924
720
990
720
495
924
924
990
560
924
792
660
770
630
886
924
660
924
630
...

result:

ok 9318 numbers

Test #3:

score: 10
Accepted
time: 4ms
memory: 1200kb

input:

107575776 7683984
9970
318 927
405 988
132 834
6 445
268 611
252 863
467 979
443 997
330 948
187 650...

output:

924
968
792
441
594
847
968
968
924
648
924
882
297
792
924
539
924
792
891
336
252
792
968
891
924
...

result:

ok 9970 numbers

Test #4:

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

input:

166418304 332836608
9808
33946 87926
10296 23243
29403 72901
38518 97074
27616 93987
24917 54546
281...

output:

86496
23088
70278
94128
93704
50986
98124
57664
84864
47064
66674
88192
76479
88192
35139
66674
9812...

result:

ok 9808 numbers

Test #5:

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

input:

63478620 437297160
9550
26045 62893
43092 86784
17496 52973
14241 51283
4367 14773
42292 88805
39658...

output:

61870
76665
51110
51110
13110
76665
76665
61870
74244
76665
24748
37122
76665
74244
76665
92805
9280...

result:

ok 9550 numbers

Test #6:

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

input:

19886000 333090500
9300
45696 93745
38251 94457
21687 95638
20536 71982
13115 26446
48043 96136
3986...

output:

81500
81500
81500
49715
20375
81500
81500
20375
40750
49715
81500
49715
49715
81500
40750
49715
3050...

result:

ok 9300 numbers

Test #7:

score: 10
Accepted
time: 4ms
memory: 1200kb

input:

202943400 304415100
9494
9035 45696
15576 69414
2237 47826
23377 88110
22630 49691
16652 65392
45948...

output:

41844
64020
47550
87175
47550
64020
92247
64020
53350
64020
52305
87175
87175
80025
95100
87175
8002...

result:

ok 9494 numbers

Test #8:

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

input:

409519616 255949760
9654
3529364 116950129
9643 832086
4776204 500233623
74 231
3881982 598796620
21...

output:

51189952
799843
51189952
209
51189952
51189952
25594976
64
51189952
168388
51189952
51189952
5118995...

result:

ok 9654 numbers

Test #9:

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

input:

203359194 67786398
9171
3979446 976089629
5599 201623
173333 837815033
57223 98444567
9 20
80 236
56...

output:

67786398
191487
67786398
67786398
18
213
67786398
67786398
2059
318246
389577
213
10974
11297733
677...

result:

ok 9171 numbers

Test #10:

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

input:

265920480 151954560
9127
413 34155
2906 181514
9946 640894
60 174
70 340
1091724 556442868
5670 3205...

output:

34040
171120
633144
160
333
37988640
316572
37988640
37988640
37988640
372
633144
37988640
245088
37...

result:

ok 9127 numbers