n, P = map(int, input().split()) A = list(map(int, input().split())) x = P ans = 0 while x < max(A): cnt = {} for a in A: b = a % x ans += cnt.get(b, 0) cnt[b] = cnt.get(b, 0) + 1 x *= P print(ans)