#include using namespace std; #include using namespace atcoder; using mint = modint998244353; //using mint = modint1000000007; using ll = long long; using ld = long double; using pll = pair; using tlll = tuple; constexpr ll INF = 1LL << 60; template bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;} template bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;} ll safemod(ll A, ll M) {return (A % M + M) % M;} ll divfloor(ll A, ll B) {if (B < 0) {return divfloor(-A, -B);} return (A - safemod(A, B)) / B;} ll divceil(ll A, ll B) {if (B < 0) {return divceil(-A, -B);} return divfloor(A + B - 1, B);} #define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false) vector factorize(ll n) { vector ret; for (ll p = 2; p * p <= n; p++) { ll e = 0; while (n % p == 0) { n /= p; e++; } if (e > 0) ret.push_back(make_pair(p, e)); } if (n > 1) ret.push_back(make_pair(n, 1)); return ret; } ll f(ll n, ll p) // n! は p で何回割り切れるか { ll ret = 0; for (ll k = p; k <= n; k *= p) { ret += n / k; } return ret; } int main() { ll N, K, M; cin >> N >> K >> M; auto PE = factorize(M); ll ans = INF; for (auto &[p, e] : PE) { ll e2 = f(N, p) - f(N - K, p) - f(K, p); ll tmp = max(0LL, e2 / e); chmin(ans, tmp); } cout << ans << endl; }