#include #include #include #include using namespace std; using ll=long long; #define rep(i,n) for(int i=0;i=0;i--) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; ll P; cin>>N>>P; vectorA(N); rep(i,N)cin>>A[i]; vectorC(30); ll q=P; rep(i,30){ if(q>1e9)break; mapmp; rep(j,N){ mp[A[j]%q]++; } for(auto[x,y]:mp)C[i]+=y*(y-1)/2; q*=P; } rep(i,29)C[i]-=C[i+1]; ll ans=0; rep(i,30)ans+=(i+1)*C[i]; cout<