import sys from collections import deque, Counter input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 n, p = mi() A = li() nowp = 1 ans = 0 for _ in range(60): nowp *= p if nowp > max(A): break a = Counter([v % nowp for v in A]) for v, c in a.items(): ans += c * (c - 1) // 2 print(ans)