from collections import Counter n, p = map(int, input().split()) a = list(map(int, input().split())) amx = max(a) pk = p ans = 0 while pk <= amx: c = Counter() for x in a: r = x % pk ans += c[r] c[r] += 1 pk *= p print(ans)