#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1.0);
long long qpow(long long a, long long b, long long p) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % p;
    a = a * a % p;
    b >>= 1;
  }
  return res;
}
long long a[N];
int main() {
  std::ios::sync_with_stdio(false);
  int n, p, k;
  while (cin >> n >> p >> k) {
    for (int i = 1; i <= n; i++) cin >> a[i];
    map<long long, long long> mp;
    for (int i = 1; i <= n; i++)
      mp[(qpow(a[i], 4, p) - k % p * a[i] % p + p) % p]++;
    map<long long, long long>::iterator it = mp.begin();
    long long ans = 0;
    for (it; it != mp.end(); it++) {
      ans += (*it).second * ((*it).second - 1) / 2;
    }
    cout << ans << endl;
  }
  return 0;
}
