#include #include #define int long long #define rep(i, n) for(i = 0; i < n; i++) using namespace std; int n, p; int a[100000]; //modは素数pの累乗 int solve(int mod) { unordered_map mp; int i; rep(i, n) mp[a[i] % mod]++; int ret = 0; for (unordered_map::iterator it = mp.begin(); it != mp.end(); it++) { int cnt = it->second; ret += cnt * (cnt - 1) / 2; } return ret; } signed main() { int i; cin >> n >> p; rep(i, n) cin >> a[i]; int mul = p; int ans = 0; while (mul <= 1000000000) { ans += solve(mul); mul *= p; } cout << ans << endl; return 0; }