題目鏈接:https://codeforc.es/problemset/problem/1188/B
題目大意:給定和長度爲的數組,問滿足中,的對數。
思路:
那麼此時問題轉換成組合數學的問題:先求出對應出現的次數,那麼:這個數對答案的貢獻則爲,用去重一下就了。
AC代碼:
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+100;
typedef long long ll;
ll qpow(ll x,ll y,ll mo){
ll ans=1;
while(y>0){
if(y&1){
ans=ans*x%mo;
}
x=x*x%mo;
y>>=1;
}
return ans;
}
ll a[maxn];
map<ll ,ll >mp;
set<ll>se;
int main()
{
ll n,p,k;
cin>>n>>p>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
ll ans=(qpow(a[i],4,p)-k*a[i]%p+p)%p;
mp[ans]++;
se.insert(ans);
}
ll sum=0;
for(auto it:se){
ll tmp=mp[it];
sum+=tmp*(tmp-1)/2;
}
cout<<sum<<endl;
return 0;
}