#嘘解法 import sys sys.setrecursionlimit(10 ** 6) 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)) f += 1 if(n != 1): prime.append((n,1)) return prime def lucas(n, k, p): if(n < p and k < p): return (n < k or n == 0) res = 0 while(n or k): r1 = n % p; n //= p r2 = k % p; k //= p res += lucas(r1, r2, p) return res prime = prime_factorize(M) ans = 10 ** 18 for p,c in prime: cnt = lucas(N, K, p) // c if(ans > cnt): ans = cnt print(ans)