Cod sursa(job #2753051)
Utilizator | Data | 20 mai 2021 20:28:42 | |
---|---|---|---|
Problema | Cbinteractiv | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.4 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, k = 0; cin >> N;
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;
}