fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6.  
  7. int solve(vector<int>A,int k,int p){
  8. int n=A.size();
  9. int cnt=0;
  10. unordered_map<int,int>mpp;
  11. for(int i=0;i<n;i++){
  12. int x=A[i];
  13. int val=pow(x,4);
  14. int required=(val%p)-((k*x)%p)+p;
  15. required=required%p;
  16. cnt+=mpp[required];
  17.  
  18. mpp[required]++;
  19. }
  20. return cnt;
  21. }
  22.  
  23. int main(){
  24. int n;
  25. cin>>n;
  26. vector<int>A(n);
  27. for(int i=0;i<n;i++){
  28. cin>>A[i];
  29. }
  30.  
  31. int k,p;
  32. cin>>k>>p;
  33. int number_of_pairs=solve(A,k,p);
  34. cout<<"Number of pairs that are valid: "<<number_of_pairs<<endl;
  35. return 0;
  36. }
Success #stdin #stdout 0s 5320KB
stdin
3
0 1 2
0 3
stdout
Number of pairs that are valid: 1