N,K,M = map(int,input().split()) def prime_factorize(n): prime = [] f = 2 while(f * f <= n): if(n % f == 0): n //= f cnt = 1 while(n % f == 0): n //= f cnt += 1 prime.append((f,cnt)) else: f += 1 if(n != 1): prime.append((n,1)) return prime def kummer(N,K,p,q): R = N - K cnt = c = 0 while(R or K): a = R % p b = K % p if(a + b + c >= p): cnt += 1 c = (a + b + c) // p else: c = 0 R //= p K //= p return cnt // q prime = prime_factorize(M) ans = 10 ** 18 for p,c in prime: cnt = kummer(N,K,p,c) if(ans > cnt): ans = cnt print(ans)