from collections import defaultdict INF = 10 ** 9 n, p = map(int, input().split()) a = list(map(int, input().split())) cnt = [defaultdict(int) for _ in range(31)] ans = 0 for i in range(n): cur = 1 for j in range(1, 31): cur *= p if cur > INF: break ans += cnt[j][a[i] % cur] cnt[j][a[i] % cur] += 1 print(ans)