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