#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include using namespace std; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); ll n,p; cin>>n>>p; vector A(n); rep(i,n) cin>>A[i]; ll ans=0; for(ll x=p;x<=1000000000;x*=p){ map m; rep(i,n){ m[A[i]%x]++; } for(auto [a,b]:m){ ans+=b*(b-1)/2; } } cout<