#嘘解法 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, cnt)) else: f += 1 if(n != 1): prime.append((n, n, 1)) return list(sorted(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[-1]]: cnt = legendre(N,K,p,c) if(ans > cnt): ans = cnt print(ans)