http://wikioi.com/problem/1553/
/************************************************************
* Author : bo_jwolf
* Last modified : 2013-08-13 19:40
* Filename : caogao.cpp
* Description :
* *********************************************************/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <cassert>
#include <ctime>
using namespace std;
int N, K;
map<long long,bool>mp;
int main() {
map<long long,bool>::iterator it;
int sum;
while (scanf("%d %d", &N, &K) == 2) {
sum = 0;
mp.clear();
int c;
for (int i = 0; i < N; ++i) {
scanf("%d", &c);
mp[c] = true;
}
int cnt;
long long t;
for (it = mp.begin(); it != mp.end(); ++it) {
cnt = 0;
long long t = it->first;
while (mp[t]) {
mp[t] = false;
t = K * t;
++cnt;
}
sum += cnt / 2;
}
printf("%d\n", N - sum);
}
return 0;
}
// File Name: 1553.cpp
// Author: bo_jwolf
// Created Time: 2013年08月13日 星期二 17时01分20秒
#include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime>
using namespace std;
#define INT long long
bool INT hash[ 2000000005 ] ;
int main()
{
INT p , temp ;
INT n ;
while( cin >> n >> p )
{
memset( hash , false , sizeof( hash ) ) ;
INT Len = 0 ;
for( INT i = 0 ; i < n ; ++i )
{
cin >> temp ;
hash[ temp ] = true ;
if( Len < temp )
Len = temp ;
}
INT Max = 0 ;
INT t = 1 , ans = 0 , sum;
for( INT i = 0 ; i < Len ; ++i )
{
sum = 0 ;
while( hash[ i ] )
{
hash[ i ] = false ;
i = p * i ;
++sum ;
}
ans += sum / 2 ;
}
cout << n - ans << endl ;
}
return 0;
}