#include<iostream>
#include<cmath>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
const double eps = 1e-6;
const int N = 2e6 + 10;
ll a[N];
ll f[N];
void solve() {
ll n, c;
scanf("%lld%lld", & n, & c);
for (int i = 0; i < n; i ++) cin >> a[i];
ll p = c;
ll ans = 0;
while(1) {
map<int, int> cnt;
for (int i = 0; i < n; i ++)
ans += (cnt[a[i] % p] ++);
if (p > (1e9) / c) break;
p *= c;
}
cout << ans * 2 << endl;
}
int main () {
int t;
t = 1;
while (t --) {
solve();
}
return 0;
}
B-DoubleSum_牛客挑战赛55 (nowcoder.com)
暂且不太理解。先放一放。看到这种形式考虑这种做法就行了。转换成剩余类