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 = set() for i in range(2,10**6+1): if M % i == 0: q.add(i) while M % i == 0: M //= i if M != 1: q.add(i) ans = float("inf") for mod in q: ans = min( ans , cont(N,mod) - cont(K,mod) - cont(N-K,mod) ) print (ans)