#include using namespace std; template map divide(T n){//素因数分解 map res; for(T i = 2; i * i <= n; i++){ while(n % i == 0){ res[i]++; n /= i; } } if(n != 1) res[n] = 1; return res; } int main(){ long long N, K, M; cin >> N >> K >> M; map m = divide(M); map cnt; for(auto [a, b] : m){ long long t = a; while(t <= N){ cnt[a] += N / t; if(t <= N / a) t *= a; else break; } t = a; while(t <= K){ cnt[a] -= K / t; if(t <= K / a) t *= a; else break; } t = a; while(t <= N - K){ cnt[a] -= (N - K) / t; if(t <= (N - K) / a) t *= a; else break; } } long long ans = N; for(auto [a, b] : m){ ans = min(ans, cnt[a] / b); } cout << ans << endl; }