N,p = map(int,input().split()) A = list(map(int,input().split())) ans = 0 k = 1 while True: C = {} for i in range(N): C[A[i]%pow(p,k)] = C.get(A[i]%pow(p,k),0)+1 if len(C)==N:break for a in C: ans += (C[a]*(C[a]-1))//2 k += 1 print(ans)