Cod sursa(job #3344574)

Utilizator hrib_the_slothAndreea Pasca hrib_the_sloth Data 3 martie 2026 02:15:14
Problema Cbinteractiv Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.38 kb
#include <bits/stdc++.h>
using namespace std;
typedef long long i8;

int main() {
  int n;
  cin >> n;

  int l = 1;
  int r = n;
  int res = 0;
  int x;
  while (l <= r) {
    int mid = (l + r) / 2;
    cout << "? " << mid << endl;
    cin >> x;

    if (x == 1) {
      r = mid - 1;
    } else {
      res = mid + 1;
      l = mid + 1;
    }
  }
  cout << "! " << res << endl;
  return 0;
}