Cod sursa(job #2751008)

Utilizator andrei_C1Andrei Chertes andrei_C1 Data 13 mai 2021 21:00:12
Problema Cbinteractiv Scor 51
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.43 kb
#include <bits/stdc++.h>
using namespace std;
int ask(int x) {
    cout << "? " << x << '\n';
    cout.flush();
    int ans;
    cin >> ans;
    return ans;
}
int main() {
    int N;
    cin >> N;
    int k = 0;
    for(int step = (N >> 1); step >= 1; step >>= 1) {
        while(step + k <= N && ask(k + step) == 0) {
            k += step;
        }
    }
    ++k;
    cout << "! " << k << '\n';
    return 0;
}