N,P=map(int, input().split()) A=list(map(int, input().split())) ans=0 for i in range(1,100): D={} PP=pow(P,i) for a in A: b=a%PP if b not in D: D[b]=0 D[b]+=1 for d in D: ans+=D[d]*(D[d]-1) if len(D)==N: break print(ans//2)