QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#53512#2584. 反回文串not_so_organic100 ✓129ms4684kbC++4.7kb2022-10-05 12:41:002022-10-05 12:41:02

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 12:41:02]
  • 评测
  • 测评结果:100
  • 用时:129ms
  • 内存:4684kb
  • [2022-10-05 12:41:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define lowbit(i) i&-i
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc() {
    static char buf[100000], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++;
}
#define gc getchar
inline ll read() {
    ll x = 0;
    char ch = gc();
    bool positive = 1;

    for (; !isdigit(ch); ch = gc())
        if (ch == '-')
            positive = 0;

    for (; isdigit(ch); ch = gc())
        x = x * 10 + ch - '0';

    return positive ? x : -x;
}
inline void write(ll a) {
    if (a < 0) {
        a = -a;
        putchar('-');
    }

    if (a >= 10)
        write(a / 10);

    putchar('0' + a % 10);
}
inline void writeln(ll a) {
    write(a);
    puts("");
}
inline void wri(ll a) {
    write(a);
    putchar(' ');
}
inline ull rnd() {
    ull ans = 0;
    For(i, 0, 5)ans = ans << 15 ^ rand();
    return ans;
}
ll mul(ll x, ll y, ll mod) {
    return ((x * y - (ll)((ld)x / mod * y + 0.5) * mod) + mod) % mod;
}
ll ksm(ll a, ll b, ll mod) {
    ll ans = 1;

    for (; b; b >>= 1) {
        if (b & 1)
            ans = mul(ans, a, mod);

        a = mul(a, a, mod);
    }

    return ans;
}
bool MR(ll n) {
    const int pr[9] = {2, 3, 5, 7, 11, 13, 17, 19, 23};

    if (n <= 1)
        return 0;

    int cnt = 0;
    ll d = n - 1;

    while (!(d & 1)) {
        cnt++;
        d >>= 1;
    }

    For(i, 0, 8) {
        if (n == pr[i])
            return 1;

        ll x = ksm(pr[i], d, n), p = x;
        For(i, 1, cnt) {
            x = mul(x, x, n);

            if (x == 1 && p != 1 && p != n - 1)
                return 0;

            p = x;
        }

        if (x != 1)
            return 0;
    }
    return 1;
}
ll f(ll x, ll c, ll n) {
    return (mul(x, x, n) + c) % n;
}
ll get(ll n) {
    const int B = 500;
    ll c = rand(), x = rand() % n, y = f(x, c, n), p = 1;

    while ((x != y) && ((p == 1))) {
        ll xx = x, yy = y, cj = 1;

        for (int i = 0; i <= B && x != y && cj; i++) {
            cj = mul(cj, abs(x - y), n);
            x = f(x, c, n);
            y = f(f(y, c, n), c, n);
        }

        ll t = __gcd(cj, n);

        if (t == 1)
            continue;
        else if (cj)
            return t;
        else {
            x = xx;
            y = yy;

            for (int i = 0; i <= B && x != y && p == 1; i++) {
                p = __gcd(abs(x - y), n);
                x = f(x, c, n);
                y = f(f(y, c, n), c, n);
            }
        }
    }

    return p;
}
map<ll, int> M;
void rho(ll n) {
    if (n == 1)
        return;

    if (MR(n)) {
        M[n]++;
        return;
    }

    ll t = get(n);

    while (t == 1 && t == n)
        t = get(n);

    rho(t);
    rho(n / t);
}
int ppp, jz;
ll ans, k, mod, pe[100], pp[100];
ll h(ll x) {
    return (x & 1) ? x : x / 2;
}
ll ycl[4][32000];
ll power(ll b) {
    ll ans = 1;
    For(i, 0, 3) {
        ans = ans * ycl[i][b % jz] % mod;
        b /= jz;
    }
    return ans;
}
ll g(ll x) {
    return power((x + 1) >> 1);
}
void dfs(int p, ll dq, ll s) {
    //cout<<p<<" "<<dq<<" "<<s<<endl;
    if (p > ppp) {
        //cout<<p<<" "<<dq<<" "<<s<<endl;
        ans = (ans + h(dq) % mod * g(dq) % mod * (s % mod + mod)) % mod;
        return;
    }

    if (pp[p] != 2)
        dfs(p + 1, dq, s * (1 - pp[p]));

    For(i, 1, pe[p]) {
        //cerr<<(i==pe[p])<<" "<<(1-pp[p])<<endl;
        dq *= pp[p];
        dfs(p + 1, dq, i == pe[p] ? s : s * (1 - pp[p]));
    }
}
int main() {
    int T = read();

    while (T--) {
        ll n = read();
        k = read(), mod = read();
        jz = pow(n, 0.25) + 3;
        For(i, 0, 3) {
            ll s;

            if (i)
                s = ycl[i - 1][jz];
            else
                s = k % mod;

            For(j, ycl[i][0] = 1, jz)ycl[i][j] = ycl[i][j - 1] * s % mod;
        }
        M.clear();
        rho(n);
        ans = ppp = 0;

        for (auto i : M) {
            pp[++ppp] = i.fi;
            pe[ppp] = i.se;
        }

        dfs(1, 1, 1);
        cout << ans << endl;
    }
}
/*
f(i)=\sum g(j)\mu(i/j)
1
9311702400 7367823578 1015387267
3 2 1000000005
3 3 1000000007
4 2 1000000009
4 3 1000000011
4 4 1000000013
5 5 1000000015
7 7 1000000017
9 9 1000000019

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 3
Accepted
time: 0ms
memory: 3600kb

input:

10
9311702400 2063322107 1032035101
9311702400 3847844404 1014424217
9311702400 6992683534 1067435323
9311702400 1356819643 1024817347
9311702400 6944668829 1042812553
9311702400 9162670852 1003177793
9311702400 6567188538 1062813337
9311702400 3910301217 1018910293
9311702400 2463242636 1018694167
...

output:

618961590
28597316
1016219343
977847638
108994801
100559666
694084378
492868358
336126742
176095716

result:

ok 10 lines

Test #2:

score: 3
Accepted
time: 3ms
memory: 3760kb

input:

10
8821612800 1108326819 1054253897
8380532160 1267663274 1043024581
8821612800 3176934458 1071245977
9311702400 6481433485 1000759783
8821612800 758922381 1073365919
8380532160 166822173 1001828119
9311702400 7367823578 1015387267
6983776800 1646145481 1030885259
8821612800 3684362555 1007309749
69...

output:

391537248
1030932075
854834302
459335922
896784901
911577797
674524325
392648220
672664689
911456800

result:

ok 10 lines

Test #3:

score: 3
Accepted
time: 5ms
memory: 3684kb

input:

10
5587021440 2127415058 1022963561
8729721000 7659635137 1016643371
7351344000 5657416354 1061115347
8380532160 5792620049 1014814861
7351344000 4242769610 1017904543
5587021440 741231880 1030997497
8031343320 1974187557 1050041869
7351344000 582269195 1046561353
7351344000 5748555565 1019161603
77...

output:

237048366
629142631
260108559
841948025
191823031
162599190
64802834
814233601
189247127
961272597

result:

ok 10 lines

Test #4:

score: 3
Accepted
time: 1ms
memory: 3708kb

input:

10
6469693230 6253588187 1032035101
6469693230 3731448124 1014424217
6469693230 2724819934 1067435323
6469693230 5537386033 1024817347
6469693230 3171489419 1042812553
6469693230 2828773282 1003177793
6469693230 3191696418 1062813337
6469693230 719103207 1018910293
6469693230 513604946 1018694167
64...

output:

938630371
649086455
941467580
785494700
357076968
66986318
592587781
440144505
347253939
264375771

result:

ok 10 lines

Test #5:

score: 3
Accepted
time: 1ms
memory: 3712kb

input:

10
6692786100 1184903319 1054253897
7138971840 6233904554 1043024581
6692786100 2656214258 1071245977
6469693230 2165071435 1000759783
6692786100 1953515781 1073365919
7138971840 2649942813 1001828119
6469693230 2585876408 1015387267
8031343320 1646145481 1030885259
6692786100 2382562055 1007309749
...

output:

362430310
584760322
869953319
276629173
646549222
879297585
384496639
889650008
891113530
71351606

result:

ok 10 lines

Test #6:

score: 3
Accepted
time: 2ms
memory: 3600kb

input:

10
892371480 808257218 1022963561
2677114440 210273217 1016643371
1338557220 1099583074 1061115347
7138971840 2688719249 1014814861
1338557220 217908770 1017904543
892371480 702433120 1030997497
1784742960 1081816077 1050041869
1338557220 211638935 1046561353
1338557220 841533445 1019161603
35694859...

output:

898680129
155530895
328828577
270244294
651496839
244787553
34900610
479462222
353920192
242259038

result:

ok 10 lines

Test #7:

score: 3
Accepted
time: 0ms
memory: 3484kb

input:

10
6469693230 3833466565 1059357283
6469693230 754927365 1036136159
6469693230 2603192085 1073567071
6469693230 4639206992 1068796243
6469693230 5517015600 1041394999
6469693230 3106392852 1015301891
6469693230 4695615325 1000386287
6469693230 2092246885 1055492153
6469693230 889003093 1014212359
64...

output:

788590260
491779719
689403583
53722625
528848033
388192896
987484818
891368409
178298076
664386522

result:

ok 10 lines

Test #8:

score: 3
Accepted
time: 4ms
memory: 3672kb

input:

10
6692786100 3771774526 1028900737
6692786100 6446972990 1002463597
6692786100 3622542947 1055976967
7138971840 4763520839 1022275453
7138971840 3860802666 1053854443
7138971840 4210388874 1049774177
6692786100 4308388670 1034920309
7138971840 4160615721 1030384631
7138971840 1025055051 1073735731
...

output:

258209706
955333108
145755558
4472599
691663194
85925478
632174667
301517080
1025049977
566245998

result:

ok 10 lines

Test #9:

score: 3
Accepted
time: 2ms
memory: 3764kb

input:

10
5354228880 3994707641 1050182537
892371480 431984969 1059422839
5354228880 4963791513 1029557359
892371480 294323989 1030188781
3569485920 1712959161 1065566561
892371480 385935628 1041335231
2677114440 1536725174 1071565279
892371480 738654189 1023834521
5354228880 4834381361 1067648243
80313433...

output:

769578319
245408447
363380756
145407027
690436473
437720110
849793084
484508795
891127810
808075938

result:

ok 10 lines

Test #10:

score: 3
Accepted
time: 2ms
memory: 3636kb

input:

10
7979869234 880839352 1035297457
8978314027 7725687764 1010851649
6003473974 3614058927 1065086513
8093088763 558240262 1036101541
7514563163 4488380730 1024457293
8987295623 1665299298 1050362507
6725389078 6724791537 1066818989
6694198723 5223088598 1023481961
9302162851 1649517328 1053299347
71...

output:

637682663
411426186
798331661
1021488669
191534605
218895374
714845656
838599880
413147483
759261190

result:

ok 10 lines

Test #11:

score: 3
Accepted
time: 19ms
memory: 3780kb

input:

10
97821761637600 65704306750166 1046841041
97821761637600 59463780551379 1010287783
97821761637600 7149419822967 1001388403
97821761637600 78654751729995 1017108451
97821761637600 63496010671264 1068952721
97821761637600 94997930077494 1036598287
97821761637600 90164458929349 1069966747
97821761637...

output:

937975310
584792240
231594977
989139483
276771022
503389932
846237376
161147283
961859777
724963376

result:

ok 10 lines

Test #12:

score: 3
Accepted
time: 19ms
memory: 3780kb

input:

10
83847224260800 65393073767891 1008804857
93163582512000 59924705614375 1008420961
83847224260800 17416796259944 1022373137
97821761637600 82478701012930 1051034311
83847224260800 5858773437789 1051518067
93163582512000 39422697574754 1062876083
97821761637600 38428821290002 1041057107
93163582512...

output:

56184649
596420001
494650147
90036534
374621716
421195622
687855255
187265420
224915504
688864198

result:

ok 10 lines

Test #13:

score: 3
Accepted
time: 18ms
memory: 3668kb

input:

10
86952677011200 31235848972059 1049970937
86642131736160 28251471830580 1016834059
80955940665600 6124775121092 1065935653
86642131736160 12615181180615 1004490881
93163582512000 81931479686275 1008289823
65214507758400 8862771921575 1004938801
86952677011200 14455900391733 1037240747
989461497024...

output:

270703194
90018264
843520812
583177614
66525787
33478275
380053450
791995644
196152868
293333471

result:

ok 10 lines

Test #14:

score: 3
Accepted
time: 14ms
memory: 3768kb

input:

10
89048857617720 57552493280366 1046841041
89048857617720 5584175331939 1010287783
89048857617720 18794867636967 1001388403
89048857617720 19961694747435 1017108451
89048857617720 67300190290504 1068952721
89048857617720 83507754901014 1036598287
89048857617720 72230469295789 1069966747
89048857617...

output:

285162165
992920507
613012802
511614681
1025574201
923288434
797130041
466760148
878381276
50499538

result:

ok 10 lines

Test #15:

score: 3
Accepted
time: 5ms
memory: 3772kb

input:

10
29682952539240 12031044006851 1008804857
59365905078480 28921935656215 1008420961
29682952539240 8799164877584 1022373137
89048857617720 87680334369850 1051034311
29682952539240 8317256865189 1051518067
59365905078480 38439304203794 1062876083
89048857617720 33537733208122 1041057107
593659050784...

output:

632625938
622664420
154768854
88437443
620002944
387993011
648216718
979385570
370715311
1039138043

result:

ok 10 lines

Test #16:

score: 3
Accepted
time: 14ms
memory: 3636kb

input:

10
96269035262400 71606734727259 1049970937
77015228209920 47505278883060 1016834059
86642131736160 77443103802692 1065935653
77015228209920 31868988233095 1004490881
59365905078480 5433826934755 1008289823
14841476269620 6249015856655 1004938801
96269035262400 14455900391733 1037240747
742073813481...

output:

683797105
991850589
115872044
364381822
499017184
36862841
469104118
182955049
831957097
843215726

result:

ok 10 lines

Test #17:

score: 3
Accepted
time: 14ms
memory: 3764kb

input:

10
89048857617720 59723364969244 1038174637
89048857617720 4324272870644 1073271281
89048857617720 31842282833961 1030927823
89048857617720 4236254270692 1040321327
89048857617720 75440686804380 1051681867
89048857617720 13202781823767 1045381861
89048857617720 8887626540892 1001900093
8904885761772...

output:

479917539
762627203
56790269
358922414
273147925
223722863
360109472
975975659
719119603
111015222

result:

ok 10 lines

Test #18:

score: 3
Accepted
time: 9ms
memory: 3636kb

input:

10
59365905078480 34450079405369 1012341877
59365905078480 46760618169023 1003287847
59365905078480 51289992595259 1040994763
89048857617720 79105592669341 1057715303
89048857617720 6170835681130 1045728847
89048857617720 60666028852502 1046728999
59365905078480 10515727173552 1020354001
89048857617...

output:

817546647
962470742
798730759
119276831
494599677
19851510
905439195
839053358
345307298
281588296

result:

ok 10 lines

Test #19:

score: 3
Accepted
time: 9ms
memory: 3680kb

input:

10
44524428808860 25396419053547 1039485857
59365905078480 23800715431124 1011919663
44524428808860 38594252365929 1068321997
59365905078480 47553672393134 1022517227
29682952539240 4126110370920 1073036683
89048857617720 84607210887856 1010508133
89048857617720 35379350268090 1032317971
44524428808...

output:

274715926
252258875
512398159
760247695
443523502
1009975639
436167870
613637989
460598323
394586949

result:

ok 10 lines

Test #20:

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

input:

10
14841476269620 13090676589743 1012553497
14841476269620 264453710949 1038849001
59365905078480 17627230584068 1056555481
29682952539240 10091814009426 1017716317
96269035262400 94345568750137 1052040307
29682952539240 2727262057754 1004833033
14841476269620 8169685928294 1053142921
77015228209920...

output:

582486331
553917379
78378867
231359269
630052741
811694173
880163209
210735871
592990019
476730798

result:

ok 10 lines

Test #21:

score: 3
Accepted
time: 129ms
memory: 4496kb

input:

10
897612484786617600 284495640150868270 1068847981
897612484786617600 335478391619138595 1016494901
897612484786617600 13834456571793948 1018602829
897612484786617600 9691686369089746 1040949647
897612484786617600 226142799520103675 1027346459
897612484786617600 791849793029350991 1039182773
897612...

output:

457168573
472221051
468339435
151258078
849570775
373822984
425358682
740061191
190938348
160636186

result:

ok 10 lines

Test #22:

score: 3
Accepted
time: 109ms
memory: 4684kb

input:

10
897612484786617600 750628014753890119 1022274893
961727662271376000 343339759123245095 1065063511
876240758958364800 89567842372889284 1048348559
897612484786617600 739359685926600051 1020838303
748010403988848000 747129712979718149 1054522943
876240758958364800 720096812936730964 1007826761
8762...

output:

1006139892
541194829
383805259
441539759
571065282
900165876
978545677
773223800
227933803
871953717

result:

ok 10 lines

Test #23:

score: 3
Accepted
time: 121ms
memory: 4584kb

input:

10
800573297242118400 68951444425902091 1017799529
970391875444992000 199763227435190697 1029579563
822811444387732800 260851727787862000 1067951513
961727662271376000 578874066870744950 1027562453
876240758958364800 258875322639262541 1019814031
897612484786617600 797990419793632458 1043657123
7480...

output:

840284005
575943149
915540875
68757590
319716110
218297899
74296337
1007971847
610976707
594636009

result:

ok 10 lines

Test #24:

score: 3
Accepted
time: 46ms
memory: 4536kb

input:

10
614889782588491410 185606883766390210 1068847981
614889782588491410 469867959240547695 1016494901
614889782588491410 148224024193203048 1018602829
614889782588491410 193525632182737876 1040949647
614889782588491410 176698421327864645 1027346459
614889782588491410 360793956254507711 1039182773
614...

output:

441700083
974347653
262659363
115319026
212003175
741460576
794813085
293394323
421208375
263674915

result:

ok 10 lines

Test #25:

score: 3
Accepted
time: 97ms
memory: 4540kb

input:

10
614889782588491410 548624160707403577 1022274893
941958815880242160 343339759123245095 1065063511
837296725226881920 89567842372889284 1048348559
614889782588491410 541582173157643931 1020838303
784965679900201800 747129712979718149 1054522943
837296725226881920 836928914131179604 1007826761
8372...

output:

759594331
993251321
781693177
323772251
532189358
644533459
586297154
837945148
442901990
405569292

result:

ok 10 lines

Test #26:

score: 3
Accepted
time: 98ms
memory: 4556kb

input:

10
418648362613440960 230535811145998411 1017799529
392482839950100900 134871880853629197 1029579563
627972543920161440 563617843688110000 1067951513
941958815880242160 638180606044146470 1027562453
837296725226881920 570427592491125581 1019814031
614889782588491410 133656259012902018 1043657123
784...

output:

440169170
823366712
642549401
737079582
15176364
148597990
485884416
478246206
610970646
377452274

result:

ok 10 lines

Test #27:

score: 3
Accepted
time: 34ms
memory: 4632kb

input:

10
614889782588491410 324528924460811372 1038327863
614889782588491410 139062845439531100 1006573649
614889782588491410 149429622085111161 1019605849
614889782588491410 7704136468202542 1042571897
614889782588491410 194109512776789555 1035103057
614889782588491410 197195421925608386 1002932869
61488...

output:

607449540
462251823
519639392
513705390
993398348
906521984
435956154
64350492
203368884
486514451

result:

ok 10 lines

Test #28:

score: 3
Accepted
time: 77ms
memory: 4556kb

input:

10
614889782588491410 146649548795430295 1067347297
784965679900201800 641086776380066458 1027646071
837296725226881920 761625763848323325 1018927451
784965679900201800 45331870490726382 1028887193
614889782588491410 86844596412647205 1025448899
941958815880242160 47322812242258689 1045401569
614889...

output:

682385411
262134291
317826658
185951453
415431054
231734034
830897915
738601535
260458924
788945003

result:

ok 10 lines

Test #29:

score: 3
Accepted
time: 72ms
memory: 4656kb

input:

10
837296725226881920 746214135604946978 1065739093
837296725226881920 666721954105236687 1013602927
313986271960080720 253103342166514610 1025189831
470979407940121080 8057809644202984 1017206623
941958815880242160 809534725951162510 1071436021
627972543920161440 189974394931876589 1073188141
78496...

output:

425252512
506664460
810973458
622148610
365806829
104978690
487663789
105824880
425218595
96144561

result:

ok 10 lines

Test #30:

score: 3
Accepted
time: 20ms
memory: 4576kb

input:

10
583319503545642502 512749524262429710 1016677360
998073919231328211 606822131952824549 1049557159
838270951561095909 344603458850435590 1045551183
792962702528464879 574929391996695121 1047345261
779189632161192841 2457787630059798 1036751830
701317505073449939 377307445983541927 1061278496
51829...

output:

917645780
583978911
209015992
587468785
90687328
924940421
770172601
999811269
258145824
74012699

result:

ok 10 lines

Test #31:

score: 3
Accepted
time: 18ms
memory: 4652kb

input:

10
505834248917738537 141616407693594960 1009821467
952544052832526078 250297268803379656 1040340227
738023676321505814 512476453624870754 1021112857
838845337456425128 535716618777509511 1019130793
585915921539974217 335652732109197511 1039612003
777449414933486322 732354432144283440 1057518331
768...

output:

335260513
247346826
224322183
853323773
533116010
426181477
972302899
306861660
913023257
107380372

result:

ok 10 lines

Test #32:

score: 3
Accepted
time: 39ms
memory: 4584kb

input:

10
999999822000007597 558103808373592802 1071304436
999999822000007597 514302866459361322 1072161713
999999812000008307 271935935809992630 1018128744
999999680000023751 477844293863885798 1007553250
999999830000006741 52166157770476248 1069531067
999999812000008307 263390963057727865 1033763571
9999...

output:

1068194904
979523748
126018720
230965172
654803417
944853826
244893616
402852528
272080445
214916791

result:

ok 10 lines

Test #33:

score: 4
Accepted
time: 38ms
memory: 4520kb

input:

10
999999726000014413 575878802009182398 1023868099
999999734000012789 44080224144018795 1015956811
999999866000004473 521838889502779856 1034478097
999999776000012519 471938167834409026 1021704011
999999812000008307 962126809746718079 1011420203
999999726000014413 849691353492228173 1009404439
9999...

output:

973078113
354818059
318341605
250107418
177689029
184526912
855020515
236059270
17353273
340876170

result:

ok 10 lines