#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<pair<ll, int>> prime_factors(ll n) {
    vector<pair<ll, int>> pf;
    ll p = 2;
    while (p * p <= n) {
        int cnt = 0;
        while (n % p == 0) {
            cnt++;
            n /= p;
        }
        if (cnt) pf.push_back(make_pair(p, cnt));
        if (p == 2) p++;
        else p += 2;
    }
    if (n > 1) pf.push_back(make_pair(n, 1));
    return pf;
}
ll find_x(ll N, ll R, pair<ll, int>& p) {
    ll C = N - R;
    ll cnt = 0;
    while (N) {
        N /= p.first;
        cnt += N;
    }
    while (C) {
        C /= p.first;
        cnt -= C;
    }
    while (R) {
        R /= p.first;
        cnt -= R;
    }
    return cnt / p.second;
}
int main() {
    ll N, R, M;
    cin >> N >> R >> M;
    vector<pair<ll, int>> pf = prime_factors(M);
    ll ans = 1e9;
    for (auto& p : pf) {
        ans = min(ans, find_x(N, R, p));
    }
    cout << ans << endl;
}