#include <bits/stdc++.h>
using namespace std;
const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng(
    (unsigned int)chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e9;
long long n, p, k;
map<long long, int> mp;
int main() {
  cin >> n >> p >> k;
  for (int i = 0; i < n; i++) {
    long long w;
    cin >> w;
    w = (w * (w * w % p * w % p - k) % p + p) % p;
    mp[w] += 1;
  }
  long long ans = 0;
  for (auto iter : mp) {
    ans += iter.second * (iter.second - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}
