require 'mathn' n = gets.chomp.to_i for m in [n - 100, 4].max..(n + 100) unless m.prime? puts m break end end