from collections import defaultdict n, p = map(int, input().split()) a = list(map(int, input().split())) t = 1 ans = 0 while t <= 10 ** 10: t *= p d = defaultdict(int) for x in a: d[x % t] += 1 for v in d.values(): ans += v * (v - 1) // 2 print(ans)