require 'prime' n = gets.to_i if Prime.prime?(n) puts "1 #{n}" return end Prime.each(n) {|p| if n % p == 0 puts "#{p} #{n / p}" return end }