#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
struct d_ {
  template <typename T>
  d_ &operator,(const T &x) {
    cerr << ' ' << x;
    return *this;
  }
  template <typename T>
  d_ &operator,(const vector<T> &x) {
    for (auto x : x) cerr << ' ' << x;
    return *this;
  }
} d_t;
ll pow4(ll first, ll m, ll k) {
  ll p = (first * first) % m;
  p = (p * p) % m;
  return (p + m - (first * k) % m) % m;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  ll n, p, k;
  cin >> n >> p >> k;
  vll A(n);
  unordered_map<ll, ll> m;
  for (ll i(0); i < n; i++) {
    cin >> A[i];
    m[pow4(A[i], p, k)]++;
  }
  ll ret = 0;
  for (auto &i : m) ret += (i.second * (i.second - 1)) / 2;
  cout << ret << endl;
  return 0;
}
