#include using namespace std; using ll = long long; #define all(A) A.begin(),A.end() using vll = vector; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) int main() { ll N,K,M,an=0; cin>>N>>K>>M; ll A=N-K; map P; for(ll i=2;i*i<=M;i++){ if(M%i==0){ while(M%i==0){ P[i]++; M/=i; } } } if(M!=1)P[M]++; ll AN=1e18; for(auto p:P){ ll T=N; ll Y=K; ll U=A; ll m=p.first; rep(i,70){ an+=(T/=m)-(Y/=m)-(U/=M); } AN=min(AN,an/p.second); an=0; } cout<