#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll N,P; cin>>N>>P; vector<int> A(N); for(int i=0;i<N;i++)cin>>A[i]; ll an=0; ll p=P; while(p<1e9+3){ map<ll,ll> M; for(int i=0;i<N;i++){ an+=M[A[i]%p]; M[A[i]%p]++; } p*=P; } cout<<an<<endl; }