Submission #49356980


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

#define SZ(x) ((int)((x).size()))
#define lb(x) ((x) & (-(x)))
#define bp(x) __builtin_popcount(x)
#define bpll(x) __builtin_popcountll(x) 
#define mkp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 2e5 + 10;
const int MAXD = 2e4 + 10;

// ll mul(ll x, ll y, ll p) {
//     return (x * y - (ll)((long double)x / p * y) * p + p) % p;
// }

ll mul(ll x, ll y, ll p) {
    return (__int128_t)x * y % p;
}

ll ksm(ll x, ll y, ll p) {
    ll res = 1;
    while (y) {
        if (y & 1) {
            res = mul(res, x, p);
        }
        x = mul(x, x, p);
        y >>= 1;
    }
    return res;
}

int n; ll P;
ll a[MAXN], ord[MAXN];
vector<ll> vecd;

ll getord(ll x) {
    ll curp = P - 1;
    for (auto p : vecd) {
        while (curp % p == 0 && ksm(x, curp / p, P) == 1) {
            curp /= p;
            // printf("cao! curp = %lld, p = %lld \n", curp, p);
        }
    }
    return curp;
}

void solve() {
	cin >> n >> P;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    
    ll curp = P - 1;
    for (ll i = 2; i * i <= curp; i++) {
        if (curp % i) {
            continue;
        }
        while (curp % i == 0) {
            curp /= i;
        }
        vecd.push_back(i);
    }
    if (curp > 1) {
        vecd.push_back(curp);
    }

    for (int i = 1; i <= n; i++) {
        ord[i] = getord(a[i]);
    }

    sort(ord + 1, ord + n + 1);

    int m = 0;
    static pair<ll, int> vecord[MAXD];
    for (int i = 1; i <= n; i++) {
        if (ord[i] == ord[i - 1]) {
            vecord[m].se++;
        }
        else {
            vecord[++m] = mkp(ord[i], 1);
        }
    }

    ll ans = 0;
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= m; j++) {
            if (vecord[j].fi % vecord[i].fi == 0) {
                ans += 1ll * vecord[i].se * vecord[j].se;
            }
        }
    }
    printf("%lld\n", ans);
}

int main() {
	int T = 1;
	while (T--) solve();
	return 0;
}

Submission Info

Submission Time
Task G - Discrete Logarithm Problems
User TLE_Automat
Language C++ 20 (gcc 12.2)
Score 600
Code Size 2173 Byte
Status AC
Exec Time 1207 ms
Memory 7044 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 12 ms 3744 KiB
random_02.txt AC 2 ms 3584 KiB
random_03.txt AC 1 ms 3704 KiB
random_04.txt AC 1 ms 3564 KiB
random_05.txt AC 1 ms 3656 KiB
random_06.txt AC 1 ms 3796 KiB
random_07.txt AC 1 ms 3656 KiB
random_08.txt AC 1 ms 3784 KiB
random_09.txt AC 1 ms 3552 KiB
random_10.txt AC 1 ms 3776 KiB
random_11.txt AC 194 ms 6740 KiB
random_12.txt AC 124 ms 6008 KiB
random_13.txt AC 328 ms 6876 KiB
random_14.txt AC 107 ms 4676 KiB
random_15.txt AC 354 ms 6740 KiB
random_16.txt AC 70 ms 4132 KiB
random_17.txt AC 435 ms 6888 KiB
random_18.txt AC 335 ms 6796 KiB
random_19.txt AC 398 ms 6888 KiB
random_20.txt AC 191 ms 5816 KiB
random_21.txt AC 1 ms 3644 KiB
random_22.txt AC 1 ms 3776 KiB
random_23.txt AC 1 ms 3832 KiB
random_24.txt AC 1 ms 3656 KiB
random_25.txt AC 126 ms 6668 KiB
random_26.txt AC 93 ms 4412 KiB
random_27.txt AC 267 ms 6884 KiB
random_28.txt AC 176 ms 5748 KiB
random_29.txt AC 358 ms 6876 KiB
random_30.txt AC 10 ms 3852 KiB
random_31.txt AC 1143 ms 7044 KiB
random_32.txt AC 1126 ms 6904 KiB
random_33.txt AC 1175 ms 6916 KiB
random_34.txt AC 1173 ms 6996 KiB
random_35.txt AC 1207 ms 7040 KiB
sample_01.txt AC 1 ms 3752 KiB
sample_02.txt AC 1 ms 3780 KiB
sample_03.txt AC 1 ms 3756 KiB