STDOUT.sync = true M = 30 n_max = 10**9 M.times do puts n_max res = gets.to_i break if res == 1 n_max /= 2 end