from collections import defaultdict import sys input = sys.stdin.readline N, P = map(int, input().split()) A = list(map(int, input().split())) p = P ans = 0 while p <= 10**10: cnt = defaultdict(int) for x in A: r = x % p ans += cnt[r] cnt[r] += 1 p *= P print(ans)