Skip to main content
Back to problems
Codeforces
Easy
Binary Search
Arrays
Math
Guess a number!

Determine the hidden number by asking whether your current guess is too high, too low, or correct.

Acceptance 0%
Problem Statement

Guess a number!

You are trying to determine a hidden integer in a known range by repeatedly making guesses. After each guess, you receive feedback telling you whether the hidden number is smaller, larger, or equal to your guess.

Your task is to find the hidden number using as few guesses as possible by choosing each next guess based on the feedback you receive.

This is an interactive-style practice problem: the essential idea is to narrow the search interval until the number is identified.

Idea

At every step, compare the current guess with the hidden value and shrink the search range accordingly. The natural strategy is binary search over the answer.

Input Format

The exact interactive protocol is unknown from the provided metadata. In general, a solution repeatedly queries a candidate number and receives feedback of the form:

  • the hidden number is smaller,
  • the hidden number is larger, or
  • the hidden number is equal.

Output Format

Output guesses according to the interactive protocol until the hidden number is identified.

Constraints

The hidden number is assumed to lie in a finite integer interval. Use a strategy that finishes in logarithmic time with respect to the size of the interval.

Examples
Sample cases returned by the problem API.

Example 1

Input

Hidden number = 42

Output

Guess 50 -> smaller
Guess 25 -> larger
Guess 37 -> larger
Guess 43 -> smaller
Guess 40 -> larger
Guess 41 -> larger
Guess 42 -> correct

Explanation

This illustrates the binary-search process: each response narrows the range until the answer is found.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.