#include using namespace std; using ll = long long; template T MUL(T a, T b){ T res; return __builtin_mul_overflow(a, b, &res)? std::numeric_limits::max() : res; } int main(){ ios::sync_with_stdio(false); cin.tie(0); ll N, P; cin >> N >> P; vector a(N); for(auto &&v : a) cin >> v; ll d = 1, ans = 0; while(MUL(d, P) <= 1'000'000'000'000'00){ d *= P; map mp; for(int i = 0; i < N; i++){ ll c = a[i] % d; ans += mp[c]++; } } cout << ans << '\n'; }