Cod sursa(job #2751010)
Utilizator | Data | 13 mai 2021 21:01:24 | |
---|---|---|---|
Problema | Cbinteractiv | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.42 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 = (1 << 30); step >= 1; step >>= 1) {
if(step + k <= N && ask(k + step) == 0) {
k += step;
}
}
++k;
cout << "! " << k << '\n';
return 0;
}