import sys input = sys.stdin.readline def prime_factorize(n): primes = [] f = 2 while(f * f <= n): if(n % f == 0): n //= f cnt = 1 while(n % f == 0): n //= f cnt += 1 primes.append((f, cnt)) f += 1 if(n != 1): primes.append((n, 1)) return primes N, K, M = map(int, input().split()) primes = prime_factorize(M) ans = 64 for p, c in primes: 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 cnt = kummer(N, K, p, c) if(ans <= cnt): continue ans = cnt print(ans)