Cod sursa(job #2896185)

Utilizator IvanAndreiIvan Andrei IvanAndrei Data 29 aprilie 2022 21:00:47
Problema Cbinteractiv Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.45 kb
#include <bits/stdc++.h>

using namespace std;

int main ()
{
    int l = 1, r;
    cin >> r;
    while (l <= r)
    {
        int m = (l + r) / 2;
        cout << "? " << m << '\n';
        int x;
        cin >> x;
        cout.flush();
        if (x == 0)
        {
            l = m + 1;
        }
        else
        {
            r = m - 1;
        }
    }
    cout << "! " << r << '\n';
    cout.flush();
    return 0;
}