from collections import defaultdict n, p = map(int, input().split()) A = list(map(int, input().split())) ans = 0 pow_p = p while pow_p < max(A) + 10: M = defaultdict(int) for i in range(n): ans += M[A[i] % pow_p] M[A[i] % pow_p] += 1 pow_p *= p print(ans)