#嘘解法 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 legendre(N,K,p,q): R = N - K cnt = c = 0 p *= q while(N): N //= p cnt += N while(K): K //= p cnt -= K while(R): R //= p cnt -= R return cnt prime = prime_factorize(M) ans = 10 ** 18 for p,c in prime: cnt = legendre(N,K,p,c) if(ans > cnt): ans = cnt print(ans)