#include <bits/stdc++.h>
using namespace std;
int op(int x, int p, int k) {
  int y = (1LL * x * x) % p;
  y = (1LL * y * y) % p;
  int z = (1LL * k * x) % p;
  return ((y - z) % p + p) % p;
}
int op2(int x, int p) { return ((1LL * x * x) % p * x) % p; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, p, k;
  cin >> n >> p >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  map<int, int> cnt1;
  map<int, int> cnt2;
  for (int i = 0; i < n; ++i) {
    ++cnt1[op(a[i], p, k)];
  }
  for (int i = 0; i < n; ++i) {
    ++cnt2[a[i]];
  }
  long long ans = 0;
  for (auto& [key, val] : cnt2) {
    ans += 1LL * val * (cnt1[op(key, p, k)] - val);
  }
  ans /= 2;
  for (auto& [key, val] : cnt2) {
    if (op2(key, p) == k) {
      ans += 1LL * val * (val - 1) / 2;
    }
  }
  cout << ans;
  return 0;
}
