#include <bits/stdc++.h>
using namespace std;
constexpr int NMAX = (1e5) * 3 + 5;
int n, p, k;
long long sol;
int a[NMAX];
map<int, int> mp;
vector<pair<int, int> > v;
void pun(pair<int, int> a) {
  int val = a.first;
  int ap = a.second;
  int nr =
      ((1LL * val % p * val % p * val % p * val % p) - 1LL * k * val % p + p) %
      p;
  sol = sol + 1LL * ap * mp[nr];
  mp[nr] += ap;
}
int main() {
  cin >> n >> p >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  sort(a + 1, a + n + 1);
  int nr = 1;
  for (int i = 2; i <= n; ++i) {
    if (a[i] == a[i - 1])
      nr++;
    else {
      v.push_back({a[i - 1], nr});
      nr = 1;
    }
  }
  v.push_back({a[n], nr});
  for (int i = 0; i < v.size(); ++i) {
    if (v[i].second < 2) continue;
    int val = v[i].first;
    int ap = v[i].second;
    if (4LL * val % p * val % p * val % p == k)
      sol += (1LL * ap * (ap - 1) / 2);
  }
  for (int i = 0; i < v.size(); ++i) pun(v[i]);
  cout << sol << '\n';
  return 0;
}
