題目鏈接: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);
}
}