Divisor game
Time limit1sMemory limit512 MB
Bob must determine Alice's hidden number k in [1,n] using at most d(n) divisibility queries, where d(n) is the optimal worst-case query count. Output a query strategy.
- Level
Medium7 of 10
- Topics
- Number theory, Binary search, Math, Implementation
- Solved
- No attempts yet
Problem
Alice and Bob invented a two-player game. At first, Alice chooses a positive integer in the range from 1 to some fixed integer . Then Bob asks questions of the form ‘Is divisible by ?’, where is a positive integer. Alice answers each such question with ‘yes’ or ‘no’. Bob wants to know what number Alice has in mind by asking as few questions as possible. Your task is to write a program that plays the game as Bob.
Let denote the minimal number of questions that have to be asked to find , regardless of what Alice chooses (for given ). Your program’s answer for a test case will be considered correct if is correctly determined using no more than questions.