#![allow(unused_imports)] use std::cmp::*; use std::collections::*; use std::io::Write; use std::ops::Bound::*; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let v = read_vec::(); let (n, k, m) = (v[0], v[1], v[2]); let mut sq = 1; for i in 1.. { if i * i > m { sq = i - 1; break; } } let primes = get_primes(sq + 1); let mut mm = m; let mut dividors = vec![]; for p in primes { if mm % p == 0 { dividors.push(p); while mm % p == 0 { mm /= p; } } } if mm > 1 { dividors.push(mm); } debug!(dividors); let ans = dividors .iter() .map(|&x| count(x, n) - count(x, n - k) - count(x, k)) .min() .unwrap(); println!("{}", ans); } fn count(p: i128, n: i128) -> i128 { let mut cur = p; let mut ret = 0; while cur <= n { ret += n / cur; cur *= p; } ret } fn get_primes(n: i128) -> Vec { let mut is_prime = vec![true; n as usize + 1]; let mut primes = Vec::new(); is_prime[0] = false; is_prime[1] = false; for i in 2..n + 1 { if is_prime[i as usize] { primes.push(i); let mut j = 2 * i; while j <= n { is_prime[j as usize] = false; j += i; } } } primes } fn read() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec() -> Vec { read::() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }