require 'prime' n = gets.to_i if Prime.prime?(n) puts n exit 0 end Prime.each(n) do |i| next if 2 == i next if 0 != n % i puts i exit 0 end