def cont(x,M): ret = 0 div = M while x >= div: ret += x // div div *= M return ret N,K,M = map(int,input().split()) q = {} for i in range(2,10**6+1): if M % i == 0: q[i] = 0 while M % i == 0: M //= i q[i] += 1 if M != 1: q[M] = 1 ans = float("inf") for mod in q: ans = min( ans , (cont(N,mod) - cont(K,mod) - cont(N-K,mod)) // q[mod] ) print (ans)