Cod sursa(job #2750832)

Utilizator AlexandruLuchianov1Alex Luchianov AlexandruLuchianov1 Data 13 mai 2021 13:09:20
Problema Cbinteractiv Scor Ascuns
Compilator py Status done
Runda Marime 0.37 kb
import sys

n = int(input())

guess = int(0)
step = int(2 ** 30)

while step > 0:
    new_guess = guess + step

    if new_guess > n:
        step = step // 2
        continue

    print("? " + str(new_guess))
    sys.stdout.flush()
    answer = int(input())
    if answer == 0:
        guess = new_guess

    step = step // 2

print("! " + str(guess + 1))
sys.stdout.flush()