from collections import defaultdict N, P = map(int, input().split()) A = list(map(int, input().split())) cnt = P ans = 0 while True: D = defaultdict(int) flag = True for a in A: ans += D[a%cnt] D[a%cnt] += 1 if cnt <= a: flag = False if flag: break cnt *= P print(ans)