题目链接: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;
}