require 'prime' p_arr = [] n = gets.strip.to_i p = n.prime_division #p p p.each do |pf| pf[1].times do p_arr << pf[0] end end min = Float::INFINITY #p p_arr (1..(p_arr.length - 1)).each do |i| p_arr.combination(i).each do |set1| #p set1 p2_arr = p_arr.clone set1.each do |n| if p2_arr.index(n) != nil p2_arr[p2_arr.index(n)] = nil end end p2_arr.compact! #p p2_arr (1..(p2_arr.length)).each do |j| p2_arr.combination(j).each do |set2| #p set2 #next if set2 == [nil] p3_arr = p2_arr.clone set2.each do |m| if p3_arr.index(m) != nil p3_arr[p3_arr.index(m)] = nil end end set3 = p3_arr.compact! #p set3 #next if set3 == [nil] set = [set1, set2, set3] #p set num = set1.inject(:*) - 1 + set2.inject(:*) - 1 if set3.length != 0 num += set3.inject(:*) - 1 end if num < min min = num end end end end end if min == Float::INFINITY print "#{n - 1}" else print "#{min}" end print " #{n - 1}\n"