Although I'm doing only searching work and for searching unordered_map<> takes O(1) time and map<>takes O(long) time Here is my tle code :)
include<bits/stdc++.h>
using namespace std;
define ll long long int
define nl "\n"
define pb push_back
define ppb pop_back
define umap unordered_map
define uset unordered_set
define lb lower_bound
define ub upper_bound
define mod1 1000000007
define v vector
define tt int TESTCASE;cin>>TESTCASE;while(TESTCASE--)
define f(i,a,b) for(ll i = (a); i <= (b); i++)
define fr(i,a,b) for(ll i = (a); i >= (b); i--)
void print(v &vect,ll len){ f(i,0,len-1)cout<<vect[i]<<" "; cout<<nl; }
ll power(ll a,ll b){ //Finding a power b.. ll ans=1; while(b){
if(b&1){ ans=a*ans; } b>>=1; a=a*a;
} return ans; } ll find_gcd(ll a,ll b){ //Taking b as divisor and a as dividend if( b==0 ) return a;
return find_gcd( b , a%b ); }
/*------------------------------------- IT'S MY WORLD :)) -----------------------------------------*/ int main() { ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL); tt{ ll n,x;cin>>n>>x;umap<ll,ll>mp; v vect(n);f(i,0,n-1){ cin>>vect[i]; mp[vect[i]]++; } sort(vect.begin(),vect.end());ll cnt=0; f(i,0,n-1){ ll temp=vect[i]; if(mp.find(temp)!=mp.end()){ if(mp[temp]!=0){ ll xxx=temp*x; if(mp.find(xxx)!=mp.end() && mp[xxx]!=0){ mp[temp]--;mp[xxx]--; } else { cnt++;mp[temp]--; } }
} } cout<<cnt<<nl; } return 0;
}