A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x* &lt; *y*) from the set, such that *y* = *x*·*k*.

You're given a set of *n* distinct positive integers. Your task is to find the size of it's largest *k*-multiple free subset.
The first line of the input contains two integers *n* and *k* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>, 1 ≤ *k* ≤ 10<sup class="upper-index">9</sup>). The next line contains a list of *n* distinct positive integers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>).

All the numbers in the lines are separated by single spaces.
import sys
import string
import math
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
from fractions import Fraction

def mi(s):
    return map(int, s.strip().split())

def lmi(s):
    return list(mi(s))

def tmi(s):
    return tuple(mi(s))

def mf(f, s):
    return map(f, s)

def lmf(f, s):
    return list(mf(f, s))

def js(lst):
    return " ".join(str(d) for d in lst)

def jsns(lst):
    return "".join(str(d) for d in lst)

def line():
    return sys.stdin.readline().strip()

def linesp():
    return line().split()

def iline():
    return int(line())

def mat(n):
    matr = []
    for _ in range(n):
        matr.append(linesp())
    return matr

def matns(n):
    mat = []
    for _ in range(n):
        mat.append([c for c in line()])
    return mat

def mati(n):
    mat = []
    for _ in range(n):
       mat.append(lmi(line())) 
    return mat

def pmat(mat):
    for row in mat:
        print(js(row))

class DSU:
    def __init__(self, n, important=None):
        '''
        n is a sequence of nodes we want to create
        a disjoint set out of.
        '''
        # If a node has itself as the parent, then it's the root.
        self.parents = {i: i for i in n}
        self.size = {i: 1 for i in n}
        self.num_components = len(n)
        self.important = important if important else set()
        self.num_edges = {i: 0 for i in n}

    def rank(self, x):
        if x in self.important:
            # Force these as the root.
            return float("inf")

        if x not in self.size:
            raise ValueError("{0} not in the set.".format(x))
        return self.size[x]

    def union(self, x, y):
        '''
        Returns the "new" parent.
        '''
        if x not in self.parents or y not in self.parents:
            raise ValueError("{0} or {1} not in the set.".format(x, y))

        x_rep = self.find(x)
        y_rep = self.find(y)
        if x_rep == y_rep:
            self.num_edges[x_rep] += 1
            return x_rep

        if self.rank(y_rep) > self.rank(x_rep):
            x_rep, y_rep = y_rep, x_rep
        self.parents[y_rep] = x_rep
        self.size[x_rep] += self.size[y_rep]
        self.num_components -= 1
        self.num_edges[x_rep] += (1 + self.num_edges[y_rep])
        return x_rep

    def find(self, x):
        if x not in self.parents:
            raise ValueError("{0} not in the set".format(x))

        node = x
        while self.parents[node] != node:
            node = self.parents[node]

        # Fix pointers while traversing up.
        while self.parents[x] != x:
            y = self.parents[x]
            self.parents[x] = node
            x = y
        return node

def main():
    _,k=mi(line())
    arr=lmi(line())
    arrs=set(arr)
    dsu=DSU(arr)
    for e,n in enumerate(arr):
        if n%k==0:
            if n//k in arrs:
                dsu.union(n,n//k)

    ans=0
    for par in dsu.parents:
        if dsu.find(par)==par:
            sz=dsu.size[par]
            if sz%2!=0:
                ans+=sz//2+1
            else:
                ans+=sz//2
    print(ans)
    
main()
