input = gets.chomp.split.map(&:to_i) a, b = input[0], input[1] (a..b).each do |v| if v % 3 == 0 || v.to_s.match(/3/) p v end end