ZR#1004

解法:

CODE:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>

using namespace std;

#define LL long long
const int N = 1e5 + 100;

inline LL fast_pow(LL a,LL b,LL p) {
    LL ans = 1;
    while(b) {
        if(b & 1) ans = ans * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return ans % p;
}
map<LL,LL> vis;
LL n,p,ans,a[N];

int main() {
    scanf("%lld%lld",&n,&p);
    for(int i = 1 ; i <= n ; i++) {
        scanf("%lld",&a[i]);
        if(4 * a[i] % p * a[i] % p == 0) continue;
        else vis[4 * a[i] % p * a[i] % p]++;
    }
    for(int i = 1 ; i <= n ; i++) {
        LL inv = fast_pow(a[i],p - 2,p);
        if(inv == 0) continue;
        ans += vis[inv];
        if(4 * a[i] % p * a[i] % p == inv) ans--;
    }
    printf("%lld\n",ans);
    //system("pause");
    return 0;
}
02-11 10:30