def f(a,N): res=0 while a: res+=a//N a//=N return res N,K,M=map(int,input().split()) print(f(N,M)-f(N-K,M)-f(K,M))