require 'prime' n, m = gets.split.map &:to_i ans = if n > 10000 c = Prime.prime_division(m).map{|pr, pow| cc = 0 _pr = pr while _pr <= n do cc += n / _pr _pr *= pr end cc/pow }.min ln = Math.log(n) n * (ln - 1) + (ln + Math.log(Math::PI) + Math.log(2))/2 - Math.log(m) * c else f = [*1..n].inject :* while f%m == 0 f /= m end Math.log f end ans *= Math.log10(Math::E) a = ans.floor b = ans % 1 puts "#{10.0**b}e#{a}"