a, b = gets.split.map(&:to_i) a.upto(b) do |num| if num % 3 == 0 then puts num next end tmp = num while tmp > 0 if tmp % 10 == 3 then puts num break end tmp /= 10 end end