from math import sqrt, ceil from collections import defaultdict N,P = map(int, input().split()) A = list(map(int, input().split())) M = max(A) ans = 0 i = 1 while pow(P, i) <= M: D = defaultdict(int) p = pow(P, i) for j in range(N): D[A[j] % p] += 1 for v in D.values(): ans += v*(v-1)//2 i += 1 print(ans)