Cod sursa(job #2751012)
Utilizator | Andrei Chertes andrei_C1 | Data | 13 mai 2021 21:03:27 |
---|---|---|---|
Problema | Cbinteractiv | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.46 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;
int step;
for(step = 1; step <= N; step <<= 1);
for(; step >= 1; step >>= 1) {
if(step + k <= N && ask(k + step) == 0) {
k += step;
}
}
++k;
cout << "! " << k << '\n';
return 0;
}