local n, p = io.read("*n", "*n") local a = {} for i = 1, n do a[i] = io.read("*n") end table.sort(a) local v = p local ans = 0 while v <= a[n] do local t = {} for i = 1, n do local ai = a[i] % v if t[ai] then ans = ans + t[ai] t[ai] = t[ai] + 1 else t[ai] = 1 end end v = v * p end print(ans)