#include using namespace std; using ll = long long; int main () { int N; ll P; cin >> N >> P; ll A[200020]; for (int i = 0; i < N; i ++) cin >> A[i]; ll xx = 1; ll mA = *max_element(A, A + N); ll ans = 0; for (int aj = 0; aj < 60; aj ++) { xx *= P; if (xx > mA) { break; } unordered_map mp; for (int i = 0; i < N; i ++) { ll a = A[i] % xx; ans += mp[a]; mp[a] ++; } } cout << ans << endl; }