input = gets #入力 num = input.split(" ").map(&:to_i) for i in num[0]..num[1] do puts i if i%3 == 0 or i/10 == 3 or i%10 == 3 #3の倍数 or 3が付く数字 end