#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int N;
    ll P;
    cin >> N >> P;
    vector<ll> A(N);
    vector<pair<int, ll>> B(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        int k = 0;
        while (A[i] % P == 0) {
            k++;
            A[i] /= P;
        }
        B[i] = {k, A[i]};
    }
    sort(B.begin(), B.end());
    ll ans = 0;
    vector<map<ll, int>> mp;
    ll now = 1;
    while (now < 1e9) {
        map<ll, int> tmp;
        mp.push_back(tmp);
        now *= P;
    }
    ll prek = -1;
    for (int i = 0; i < N; i++) {
        ll k = B[i].first, m = B[i].second;
        ans += k * (N - i - 1);
        if (k != prek) {
            for (int i = 0; i < mp.size(); i++) {
                mp[i].clear();
            }
        }
        ll p = P;
        int j = 0;
        while (p < 1e9) {
            ans += mp[j][m % p];
            mp[j][m % p]++;
            j++;
            p *= P;
        }
        prek = k;
    }
    cout << ans << endl;
    return 0;
}