import collections N,P = map(int, input().split()) A = list(map(int, input().split())) ans = 0 for i in range(1,50): p = P**i C = collections.Counter() for a in A: C[a%p]+=1 for k,v in C.items(): ans+=v*(v-1)//2 print(ans)