n, k, m = map(int, input().split()) Prime = [] f = 2 while f * f <= m: if m % f == 0: cnt = 1 m //= f while m % f == 0: m //= f cnt += 1 Prime.append((f, cnt)) f += 1 if m != 1: Prime.append((m, 1)) def legendre(n, k, p, cnt): r = n - k ans = 0 while n: n //= p ans += n while k: k //= p ans -= k while r: r //= p ans -= r return ans // cnt ans = 10**18 for prime, cnt in Prime: cnt = legendre(n, k, prime, cnt) ans = min(ans, cnt) print(ans)