#include using namespace std; int main() { int n, p; cin >> n >> p; vector a(n); for(auto &e : a) cin >> e; int64_t ans = 0; for(int64_t pow = p; pow <= 1e9 + 1; pow *= p) { unordered_map hm; for(auto e : a) hm[e % pow] += 1; for(auto e : hm) { ans += 1LL * e.second * (e.second - 1) / 2; } } cout << ans << endl; return 0; }