import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int p = Integer.parseInt(sa[1]); sa = br.readLine().split(" "); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); } br.close(); long ans = 0; long p2 = p; while (p2 <= 1000000000) { Map map = new HashMap<>(); for (int i = 0; i < n; i++) { int k = (int) (a[i] % p2); int v = map.getOrDefault(k, 0); ans += v; map.put(k, v + 1); } p2 *= p; } System.out.println(ans); } }