#include using namespace std; using ll = long long; using db = long double; using ch = char; using bl = bool; using st = string; using pll = pair; using psl = pair; using vst = vector; using vch = vector; using vvch = vector; using vbl = vector; using vvbl = vector; using vdb = vector; using vpll = vector; using vpsl = vector; using vi = vector; using vvi = vector; using vvvi = vector; using vvvvi = vector; using vll = vector; using vvll = vector; using vvvll = vector; using vvvvll = vector; using vvvvvll = vector; #define all(A) A.begin(),A.end() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rrep(i,a,b) for(int i=(ll)(a);i<=(ll)(b);i++) int main() { ll N,P; cin>>N>>P; ll p=P; vll list; while(p<1e9){ list.push_back(p); p*=P; } ll n=list.size(); vector> A(n); rep(i,N){ ll a; cin>>a; rep(j,n){ A[j][a%list[j]]++; } } ll ans=0; rep(j,n){ for(auto x:A[j]){ ll y=x.second; ans+=y*(y-1)/2; } } cout << ans << endl; return 0; }