template <classT> inlinevoidread(T &x) { x = 0; int f = 0; char ch = getchar(); while (!isdigit(ch)) { f |= ch == '-'; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } x = f ? -x : x; return ; }
typedeflonglong LL; typedefunsignedlonglong uLL;
std::map<uLL, bool> mp; uLL a[100010]; uLL n, k, ans, max;
intmain(){ read(n), read(k); max = 9223372036854775807 / k; for (int i = 1; i <= n; ++i) read(a[i]), mp[a[i]] = true; std::sort(a + 1, a + n + 1); for (std::map<uLL, bool>::iterator it = mp.begin(); it != mp.end(); ++it) { if (it -> second == true) { int x = 0, y = 0, j = 1; uLL now = it -> first; while (mp[now]) { if (j % 2) ++x; else ++y; ++j; mp[now] = false; if (now >= max) break; now *= k; } ans += std::max(x, y); } } printf("%llu\n", ans); return0; }