import scala.annotation.tailrec import scala.io.StdIn.* import scala.math.min def calcFactorInFactorial(n: Long, m: Long): Long = n match case 0L => 0 case _ => n / m + calcFactorInFactorial(n / m, m) def calcPrimeFactor(value: Long): List[(Long, Int)] = @tailrec def inner(v: Long, p: Long, result: List[(Long, Int)]): List[(Long, Int)] = if p * p > v then if v > 1 then (v, 1)::result else result else if v % p == 0 then var e = 0 var r = v while r % p == 0 do e += 1 r /= p inner(r, p + 1, (p, e)::result) else inner(v, p + 1, result) inner(value, 2, Nil) @main def main = val Array(n, k, m) = readLine().split(' ').map(_.toLong) var result = Long.MaxValue for (p, e) <- calcPrimeFactor(m) do val cFactor = calcFactorInFactorial(n, p) - calcFactorInFactorial(k, p) - calcFactorInFactorial(n - k, p) result = min(result, cFactor / e) println(result)