题目链接:https://codeforces.com/problemset/problem/1188/B
题目大意:给出n个元素的数组A。求有多少对(i,j)满足(A[i]+A[j])*(A[i]^2+A[j]^2)%P=k。
思路:很巧妙的思路,转化步骤:
所以,我们只需要遍历数组,对于A[i]找是否存在A[j]满足上面的式子即可。
ACCode:
map<ll,ll> Cnt;
int n;ll p,k;
int main(){
while(~scanf("%d%lld%lld",&n,&p,&k)){
Cnt.clear();
ll ans=0;
for(int i=1;i<=n;++i){
ll x;scanf("%lld",&x);
ll tmp=x*x%p;tmp=tmp*tmp%p;tmp=(tmp-(k*x%p)+p)%p;
// printf("tmp=%lld Cnt[tmp]=%lld\n",tmp,Cnt[tmp]);
ans+=Cnt[tmp];
Cnt[tmp]++;
}printf("%lld\n",ans);
}
}