ok = 1 ng = 10 ** 9 + 1 while (ok - ng).abs >= 2 x = (ok + ng) / 2 STDOUT.puts("? #{x}") STDOUT.flush res = gets.to_i if res == 1 ok = x else ng = x end end puts "! #{ok}"