Cod sursa(job #2750834)
Utilizator | Data | 13 mai 2021 13:19:07 | |
---|---|---|---|
Problema | Cbinteractiv | Scor | Ascuns |
Compilator | c-64 | Status | done |
Runda | Marime | 0.46 kb |
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
int guess = 0;
int step = (1 << 30);
for(; step > 0; step /= 2)
{
int nguess = guess + step;
if(nguess > n)
continue;
printf("? %d\n", nguess);
fflush(stdout);
int answer;
scanf("%d", &answer);
if(answer == 0)
guess = nguess;
}
printf("! %d\n", guess + 1);
fflush(stdout);
return 0;
}