Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- int main()
- {
- ll t; cin >> t;
- while (t--)
- {
- ll n, x, ans = 0; cin >> n >> x;
- vector<ll> v(n);
- map<ll, ll> m;
- for (ll i = 0; i < n; i++)
- {
- cin >> v[i];
- m[v[i]]++;
- }
- sort(v.begin(), v.end());
- for (ll i = 0; i < n; i++)
- {
- if (m[v[i]] == 0) continue;//already taken
- else//not taken
- {
- ll temp = (x * v[i]);
- m[v[i]]--;//mark v[i] as taken
- //we need to check whether temp is present in the map or not
- if (m.find(temp) != m.end())
- {
- if (m[temp] >= 1) m[temp]--;//taken
- else ans++;
- }
- else
- {
- ans++;
- }
- }
- }
- // t.c>O(n*log(number of keys))>O(nlogn).
- cout << ans << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement