#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  map<int, vector<int>> b;
  if (k == 1) {
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      b[x].push_back(1);
    }
    long long ans = 0;
    for (auto it = b.begin(); it != b.end(); it++) {
      long long sz = it->second.size();
      for (int i = 1; i < sz - 1; i++) {
        ans += (long long)((long long)i * (long long)(sz - i - 1));
      }
    }
    cout << ans << "\n";
    return 0;
  }
  int zer = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    int r = 0;
    if (x == 0) {
      zer++;
      continue;
    }
    b[x].push_back(r);
    while (x % k == 0) {
      r++;
      x /= k;
      if (r >= 4) break;
      b[x].push_back(r);
    }
  }
  long long ans = 0;
  for (int i = 1; i < zer - 1; i++) {
    ans += (long long)((long long)i * (long long)(zer - i - 1));
  }
  for (auto it = b.begin(); it != b.end(); it++) {
    vector<int> e = it->second;
    vector<int> z(e.size()), t(e.size());
    for (int i = 0; i < e.size(); i++) {
      if (i) z[i] = z[i - 1];
      if (e[i] == 0) z[i]++;
    }
    for (int i = e.size() - 1; i >= 0; i--) {
      if (i + 1 < e.size()) t[i] = t[i + 1];
      if (e[i] == 2) t[i]++;
    }
    for (int i = 0; i < e.size(); i++) {
      if (e[i] == 1) ans += (long long)((long long)z[i] * (long long)t[i]);
    }
  }
  cout << ans << "\n";
}
