from collections import defaultdict N,K,M = map(int,input().split()) class get_prime():#使うたびにクラスの定義が必要。self.revの使い回しNG def __init__(self): self.rev = [] def prime(self,n): if n == 1: return self.rev for i in range(2,int(n**0.5)+1): if n % i == 0: self.rev.append(i) self.prime(int(n/i)) break else: self.rev.append(n) return self.rev gp = get_prime() mp = gp.prime(M) pdic = defaultdict(int) for p in mp: pdic[p] += 1 def f(l,r,x,p): al = (l + pow(p,x) -1) // pow(p,x) al = max(al,1) ar = r //pow(p,x) if ar >= 1 and al <= ar: return ar - al + 1 else: return 0 def g(l,r,p): x = 1 res = 0 while pow(p,x) <= r: res += f(l,r,x,p) x += 1 return res INF = float('inf') UP = INF DOWN = INF for p in pdic.keys(): up = g(N-K+1,N,p)//pdic[p] down = g(1,K,p) //pdic[p] UP = min(UP,up) DOWN = min(down,down) print(UP - DOWN)