/* -*- coding: utf-8 -*- * * 2260.cc: No.2260 Adic Sum - yukicoder */ #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; /* typedef */ typedef long long ll; typedef unordered_map umii; /* global variables */ int as[MAX_N]; umii acs; /* subroutines */ /* main */ int main() { int n, p; scanf("%d%d", &n, &p); int maxa = 0; for (int i = 0; i < n; i++) { scanf("%d", as + i); maxa = max(maxa, as[i]); acs[as[i]]++; } int ep = 1; while ((ll)ep * p <= maxa) ep *= p; ll sum = 0; while (ep > 0) { umii bcs; for (auto [ai, ci]: acs) { sum += (ll)ci * (ci - 1) / 2; bcs[ai % ep] += ci; } swap(acs, bcs); ep /= p; } printf("%lld\n", sum); return 0; }