#include <iostream>
#include <fstream>
using namespace std;
ifstream f("puterik.in");
ofstream g("puterik.out");
unsigned int n, k, i, j=0, p, temp, num, v[101];
int main()
{
f >> n >> k;
for (i=1; i<=n; ++i)
{
f >> num;
p=1;
if (num==1) { ++j; v[j]=1;}
else
{
while (p<num)
{
p*=k;
}
if (p==num) {++j; v[j]=num; }
}
}
n=j;
for (i=1; i<n; ++i)
{
for (j=i+1; j<=n; ++j)
{
if (v[j]<v[i])
{
temp=v[i]; v[i]=v[j]; v[j]=temp;
}
}
}
for (i=1; i<=n; ++i)
g << v[i] << " ";
}