require 'prime' N, K, M = gets.split.map(&:to_i) ans = Float::INFINITY def f(n, e, c) cnt = 0 while n > 0 n /= e cnt += n end cnt / c end M.prime_division.each do |e, c| v = 0 v += f(N, e, c) v -= f(K, e, c) v -= f(N - K, e, c) ans = v if ans > v end puts ans