Submission #49182395


Source Code Expand

#include<bits/stdc++.h>
using namespace std;

using ll=long long;
inline int read(){int f=1,x=0;char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}while(isdigit(c)){x=x*10+c-'0';c=getchar();}return x*f;}
template <class T> inline T read(){T f=1,x=0;char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}while(isdigit(c)){x=x*10+c-'0';c=getchar();}return x*f;}

void getFactor(ll p,vector<ll>& fp){
    for(ll i=2;i*i<=p;i++){
        if(p%i==0){
            fp.push_back(i);
            while(p%i==0)p/=i;
        }
    }
    if(p>1)fp.push_back(p);
}

ll ksm(ll a,ll b,ll p){
    ll r = 1;
    while(b){
        if(b&1)r=(__int128_t)r*a%p;
        a=(__int128_t)a*a%p;
        b>>=1;
    }
    return r;
}

int main(){
    int n=read(); ll p=read<ll>();

    vector<ll> fp; // phi(p) 的因数
    getFactor(p-1,fp);

    map<ll,int> cnt; // 每个阶的出现次数
    for(int i=1;i<=n;i++){
        ll a=read<ll>();
        ll ord = p-1;
        for(auto f:fp){
            while(ord%f==0 && ksm(a,ord/f,p)==1)ord/=f;
        }
        cnt[ord]++;
    }

    ll ans = 0;
    for(auto [o1,c1]:cnt)for(auto [o2,c2]:cnt){
        if(o1%o2==0)ans+=(ll)c1*c2;
    }
    printf("%lld\n",ans);

    return 0;
}

Submission Info

Submission Time
Task G - Discrete Logarithm Problems
User LinLeXiao
Language C++ 20 (gcc 12.2)
Score 600
Code Size 1284 Byte
Status AC
Exec Time 1847 ms
Memory 4308 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 38
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 1 ms 3672 KiB
random_02.txt AC 1 ms 3560 KiB
random_03.txt AC 1 ms 3676 KiB
random_04.txt AC 1 ms 3676 KiB
random_05.txt AC 1 ms 3592 KiB
random_06.txt AC 2 ms 3584 KiB
random_07.txt AC 1 ms 3668 KiB
random_08.txt AC 1 ms 3616 KiB
random_09.txt AC 1 ms 3592 KiB
random_10.txt AC 1 ms 3500 KiB
random_11.txt AC 137 ms 3548 KiB
random_12.txt AC 82 ms 3604 KiB
random_13.txt AC 272 ms 3556 KiB
random_14.txt AC 87 ms 3676 KiB
random_15.txt AC 297 ms 3664 KiB
random_16.txt AC 59 ms 3592 KiB
random_17.txt AC 376 ms 3672 KiB
random_18.txt AC 279 ms 3560 KiB
random_19.txt AC 330 ms 3596 KiB
random_20.txt AC 153 ms 3504 KiB
random_21.txt AC 1 ms 3492 KiB
random_22.txt AC 1 ms 3668 KiB
random_23.txt AC 1 ms 3548 KiB
random_24.txt AC 1 ms 3548 KiB
random_25.txt AC 72 ms 3668 KiB
random_26.txt AC 80 ms 3616 KiB
random_27.txt AC 209 ms 3552 KiB
random_28.txt AC 136 ms 3592 KiB
random_29.txt AC 324 ms 3672 KiB
random_30.txt AC 7 ms 3600 KiB
random_31.txt AC 1626 ms 4184 KiB
random_32.txt AC 1605 ms 4068 KiB
random_33.txt AC 1749 ms 4276 KiB
random_34.txt AC 1790 ms 4300 KiB
random_35.txt AC 1847 ms 4308 KiB
sample_01.txt AC 1 ms 3608 KiB
sample_02.txt AC 1 ms 3672 KiB
sample_03.txt AC 1 ms 3616 KiB