#include <stdio.h>
#include <stdlib.h>

int cmp_ll (const void *ap, const void *bp) {
  long long a = *(long long *)ap;
  long long b = *(long long *)bp;
  
  if (a < b) {
    return -1;
  }
  
  if (a > b) {
    return 1;
  }
  
  return 0;
}

int main () {
  int n = 0;
  long long p = 0LL;
  long long a[100000] = {};
  
  int res = 0;
  
  long long ans = 0LL;
  long long rem[100000][2] = {};
  
  long long max = 0LL;
  long long pow = 1LL;
  
  res = scanf("%d", &n);
  res = scanf("%lld", &p);
  for (int i = 0; i < n; i++) {
    res = scanf("%lld", a+i);
    if (a[i] > max) {
      max = a[i];
    }
  }
  
  while (pow <= max/p) {
    int ucnt = 1;
    pow *= p;
    for (int i = 0; i < n; i++) {
      rem[i][0] = a[i]%pow;
    }
    qsort(rem, n, sizeof(long long)*2, cmp_ll);
    
    rem[0][1] = 1LL;
    for (int i = 1; i < n; i++) {
      if (rem[i-1][0] != rem[i][0]) {
        rem[ucnt][0] = rem[i][0];
        rem[ucnt][1] = 0LL;
        ucnt++;
      }
      ans += rem[ucnt-1][1];
      rem[ucnt-1][1] += 1LL;
    }
  }
  
  printf("%lld\n", ans);
  return 0;
}