/* * Author: nskybytskyi * Time: 2022-01-13 15:08:45 */ #include using namespace std; int main() { cin.tie(0)->sync_with_stdio(0); int64_t n, k, m; cin >> n >> k >> m; map pp; for (int d = 2; d * 1ll * d <= m; ++d) { while (m % d == 0) { ++pp[d]; m /= d; } } if (m > 1) { ++pp[m]; } auto nu = [&] (int64_t x, int64_t p) -> int64_t { int64_t ans = 0; while (x) { ans += x / p; x /= p; } return ans; }; auto nu2 = [&] (int64_t x, const map& pp) -> int64_t { int64_t mn = numeric_limits::max(); for (auto [k, v] : pp) { mn = min(mn, nu(x, k) / v); } return mn; }; cout << nu2(n, pp) - nu2(k, pp) - nu2(n - k, pp) << "\n"; return 0; }