This page is still under construction.

Parts of this page are still being built. What you see may change.

Divisor game

Time limit1sMemory limit512 MB

Summary
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 kk in the range from 1 to some fixed integer nn. Then Bob asks questions of the form ‘Is kk divisible by mm?’, where mm 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 d(n)d(n) denote the minimal number of questions that have to be asked to find kk, regardless of what kk Alice chooses (for given nn). Your program’s answer for a test case will be considered correct if kk is correctly determined using no more than d(n)d(n) questions.

Examples1

  1. Example 1

    Input
    1
    
    Expected output
    0