UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#214587#2809. 去发现新的最小公约吧a_sad_soul0111ms1644kbC++11806b2024-11-20 19:19:492024-11-20 23:02:10

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
const int N = 2e5+10;
vector<ll>p;
bool vis[N];

void Init(){
    for(ll i=2;i<N;++i){
        if(!vis[i])p.push_back(i),vis[i]=1;
        for(ll v:p){
            if(i*v>=N)break;
            vis[i*v]=1;
            if(i%v==0)break;
        }
    }
}
ll calc(ll x){
    bool sus=0;
    ll ans=x;
    for(ll v:p){
        if(v*v>x)break;
        if(x%v)continue;
        sus=1;ans=ans/v;ans=ans*(v-1);
    }
    if(!sus)return x-1;
    return ans;
}
int main(){
    int T;scanf("%d",&T);
    Init();
    while(T--){
        ll a,m;scanf("%lld%lld",&a,&m);ll k=gcd(a,m);
        printf("%lld\n",calc(m/k));
    }
    
    return 0;
}

Details

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

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 1644kb

input:

100
8 4
6 2
5 2
5 1
4 4
3 6
2 2
7 8
8 7
10 7
4 2
6 6
1 10
10 4
10 5
4 1
7 4
1 2
8 6
1 7
1 4
7 4
3 10...

output:

0
0
1
0
0
1
0
4
6
6
0
0
5
1
0
0
2
1
2
6
2
2
5
6
0
0
6
2
0
2
2
0
6
4
1
4
0
2
2
2
4
0
0
4
0
2
6
2
6
2
...

result:

wrong answer 1st lines differ - expected: '1', found: '0'

Test #2:

score: 0
Wrong Answer
time: 3ms
memory: 1644kb

input:

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

output:

0
0
2
4
4
0
0
2
0
2
6
4
1
4
0
0
0
2
6
0
4
0
5
2
4
4
1
2
6
1
2
1
6
2
1
2
0
2
0
4
1
5
1
0
1
1
3
4
2
6
...

result:

wrong answer 1st lines differ - expected: '1', found: '0'

Test #3:

score: 0
Wrong Answer
time: 3ms
memory: 1644kb

input:

100
236 591
570 152
211 246
425 284
417 411
226 543
288 381
897 378
20 532
711 277
34 734
70 255
750...

output:

394
2
82
142
136
362
126
36
114
276
366
34
8
360
482
156
160
200
18
13
276
186
946
700
36
28
44
262
...

result:

wrong answer 1st lines differ - expected: '392', found: '394'

Test #4:

score: 0
Wrong Answer
time: 3ms
memory: 1644kb

input:

100
660 565
675 802
944 437
673 25
902 884
274 689
380 901
273 236
807 467
390 60
692 592
596 976
23...

output:

112
401
414
20
192
636
848
118
466
1
74
122
106
110
58
486
310
86
568
84
82
158
248
83
846
446
246
1...

result:

wrong answer 2nd lines differ - expected: '400', found: '401'

Test #5:

score: 0
Wrong Answer
time: 3ms
memory: 1640kb

input:

100
854 59
565 564
467 216
670 462
138 150
907 217
249 167
539 865
530 621
670 837
329 443
122 228
6...

output:

58
188
72
120
20
186
166
692
396
558
442
38
96
28
148
136
86
42
660
404
2
356
138
158
24
192
902
53
...

result:

wrong answer 2nd lines differ - expected: '184', found: '188'

Test #6:

score: 0
Wrong Answer
time: 3ms
memory: 1640kb

input:

100
478 213
187 542
661 149
341 842
442 974
604 256
944 111
571 319
941 705
453 42
205 811
727 860
9...

output:

142
271
148
421
486
32
74
290
376
7
810
344
690
346
120
138
432
40
16
418
906
17
716
204
630
79
29
3...

result:

wrong answer 1st lines differ - expected: '140', found: '142'

Test #7:

score: 0
Wrong Answer
time: 3ms
memory: 1644kb

input:

100
2646495639 83073
7823694236 39102
881727324 40751
5863530312 76599
9543772391 54826
7121248446 9...

output:

27690
10584
40750
5674
27066
2302
18340
20736
91024
46668
5466
38304
41356
15666
29376
3046
29520
12...

result:

wrong answer 4th lines differ - expected: '5672', found: '5674'

Test #8:

score: 0
Wrong Answer
time: 3ms
memory: 1644kb

input:

100
806019626 27134
9014848910 45923
4669150950 62049
1308235830 62695
5818631975 39455
9158335197 7...

output:

13566
43506
18144
12538
606
25920
10704
694
976
10536
432
708
28198
10369
14172
1248
2012
37656
5286...

result:

wrong answer 2nd lines differ - expected: '43488', found: '43506'

Test #9:

score: 0
Wrong Answer
time: 3ms
memory: 1640kb

input:

100
6554053173 22625
8911041785 51685
4277406929 90205
9387326879 63230
2818802968 71777
3597527462 ...

output:

18100
10336
72164
25292
71776
70862
8380
81438
42246
21062
9710
82
23054
10216
5892
7740
75796
9528
...

result:

wrong answer 1st lines differ - expected: '18000', found: '18100'

Test #10:

score: 0
Wrong Answer
time: 3ms
memory: 1640kb

input:

100
6459050216 95926
2862928574 67445
6637029072 36117
7180652465 82640
7389019538 14217
9372556634 ...

output:

47962
44160
8026
8264
8124
28476
1680
188
91920
38842
22452
8204
24150
50114
38566
396
23772
726
880...

result:

wrong answer 3rd lines differ - expected: '8024', found: '8026'

Test #11:

score: 0
Wrong Answer
time: 9ms
memory: 1640kb

input:

100
4045462519 6079203834
3592763471 4209040120
867154445 2049504817
3901368197 9681318674
579119579...

output:

1838452000
1679616960
2049504816
4840659337
3936988800
290668732
334972936
635791416
296683180
19876...

result:

wrong answer 2nd lines differ - expected: '1679610240', found: '1679616960'

Test #12:

score: 0
Wrong Answer
time: 9ms
memory: 1644kb

input:

100
9123862244 9980053608
7985310706 2228386162
7603155722 8812166405
5630356584 4148773838
21142841...

output:

117036876
1061738160
6042628392
1885191420
186161566
15574722
2154381984
1451762076
4390921540
73304...

result:

wrong answer 1st lines differ - expected: '117036744', found: '117036876'

Test #13:

score: 0
Wrong Answer
time: 9ms
memory: 1640kb

input:

100
7426491555 2763484756
5457391985 6457160532
534914118 1572249269
2775997991 3809315223
888272698...

output:

1351638240
2029837152
1548782862
2082060288
862570554
8859497696
3089815960
540984912
9420768858
340...

result:

wrong answer 2nd lines differ - expected: '2029832448', found: '2029837152'

Test #14:

score: 0
Wrong Answer
time: 6ms
memory: 1640kb

input:

100
9075853678 102993875
3010884417 2979594557
5930330168 4871508518
7600226984 8940737887
118514897...

output:

81266400
2979594556
2432912072
8921427438
766488800
1094959368
1766386812
4780329280
320288736
32923...

result:

wrong answer 1st lines differ - expected: '81259200', found: '81266400'

Test #15:

score: 0
Wrong Answer
time: 9ms
memory: 1644kb

input:

100
4021096645 5084700743
2505598974 4226942433
2028384176 2927433426
6560727784 4700774690
85539163...

output:

5084700742
1189168128
975811142
1880075160
1501398760
2622853120
4345512120
4710017280
2500807112
78...

result:

wrong answer 3rd lines differ - expected: '975811140', found: '975811142'

Test #16:

score: 0
Wrong Answer
time: 9ms
memory: 1640kb

input:

100
5394932023 3200344581
8199663693 1374607804
3913573573 1880621978
4329635001 2811700871
25796777...

output:

1828768332
687129060
940186428
2408914080
537165438
3930587136
4972893568
2088039744
6420971520
1684...

result:

wrong answer 1st lines differ - expected: '1828768320', found: '1828768332'

Test #17:

score: 0
Wrong Answer
time: 6ms
memory: 1640kb

input:

100
4421181565 7950164025
7271383279 1281340308
6720617512 8240572244
5246156506 2633726799
44108925...

output:

841544080
424877240
2025225382
1506816000
4567130712
1220459298
488237027
4817608240
3011788800
7978...

result:

wrong answer 1st lines differ - expected: '841543040', found: '841544080'

Test #18:

score: 0
Wrong Answer
time: 9ms
memory: 1644kb

input:

100
64792226 2094307560
9263645727 6840282932
498184184 7131019629
1288538432 4944555527
6572306238 ...

output:

277689600
488450304
4740391272
4942708476
2825385264
786164268
944472672
729907200
9763288588
187931...

result:

wrong answer 2nd lines differ - expected: '488443392', found: '488450304'

Test #19:

score: 0
Wrong Answer
time: 9ms
memory: 1644kb

input:

100
6673224472 4793077122
343436275 556644377
4195412270 4516001680
5415513582 589610523
3988294799 ...

output:

1597692374
556612188
225701352
194510688
3799984106
2110208040
6360951996
123869992
5499574386
13232...

result:

wrong answer 1st lines differ - expected: '1597692372', found: '1597692374'

Test #20:

score: 0
Wrong Answer
time: 6ms
memory: 1644kb

input:

100
4194270818 7289820928
7777260632 7890730149
3249835305 2579410381
3029031009 7280770225
70482421...

output:

1594644480
4812521472
2560582568
5823738320
4389578704
128654760
3138972308
1129075200
4383846368
19...

result:

wrong answer 3rd lines differ - expected: '2560582432', found: '2560582568'