n,k,m = map(int,input().split()) def prime_factorization(w,d): cnt = 2 while w > 1: if cnt > int(w ** (1/2)): d[w] += 1 break while w % cnt == 0: d[cnt] += 1 w //= cnt cnt += 1 from collections import defaultdict m_d = defaultdict(int) prime_factorization(m,m_d) def f_prime(N,K): d = defaultdict(int) def cul(nn,pm): for key in m_d.keys(): cnt = 1 while key ** cnt <= nn: if pm : d[key] += nn // (key ** cnt) else: d[key] -= nn // (key ** cnt) cnt += 1 cul(N,True) cul(N-K,False) cul(K,False) return d n_d = f_prime(n,k) ans = 10000 for key in m_d.keys(): ans = min(ans,n_d[key]//m_d[key]) print(ans)