← All problemsSign in

Guess the Prime!

CodeChefRating 2055Open on judge ↗

**This is an interactive problem.** Shef chose some prime number $P$ between $2$ and $10^9$ inclusive. You want to guess it. Before that, you may ask Shef at most $M$ questions, since he is quite busy. In each question, you tell Shef an integer $x$ ($1 \le x \le 10^9$) and Shef tells you $x^2$ modulo $P$. At the end, you guess Shef's prime $P$ and he tells you if your guess was correct. However

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start