Cod sursa(job #3183710)

Utilizator NToniBoSSNicolae Tonitza NToniBoSS Data 12 decembrie 2023 19:50:42
Problema Cbinteractiv Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.43 kb
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, pas = 1 << 30, sol = 0;
    cin >> n;
    int st = 1, dr = n + 1;
    while(pas){
        if(sol + pas <= n){
            cout << "? " << sol + pas;
            cout.flush();
            int x;
            cin >> x;
            if(x == 0)
                sol += pas;
        }
        pas /= 2;
    }
    cout << "! " << sol + 1 << endl;
    cout.flush();
    return 0;
}