Wizard of Odds
InterviewTime limit2sMemory limit512 MB
Given N possible secret numbers and K yes/no questions, decide whether K adaptive questions always identify the number, where K questions distinguish at most 2^K outcomes.
- Level
Medium4 of 10
- Topics
- Math, Binary search, Bit manipulation, Implementation
- Solved
- No attempts yet
Problem
A long journey ends at the hall of the Wizard of Odds, who promises to grant any wish if you solve one puzzle.
The wizard first tells you two integers and . He then secretly picks an integer from 1 to inclusive and keeps it to himself.
Your goal is to name that secret number correctly. Before naming it you may ask questions that the wizard answers with true or false, for example "is the number even", "is the number between 7 and 10", "is the number 17 or 22", or "is the number prime". The wizard always answers honestly. Once all answers are in you must name one number. Name it correctly and your wish is granted. Name it wrongly and you become a flying monkey.
Formally, a question is a function from to the two values true and false, and the wizard tells you the value of that function at his secret number. You may choose each question after seeing the answers to the earlier ones.
Given and , decide whether questions always pin down the secret number, no matter which number the wizard picked.
Input
The first line contains two integers and separated by a single space. (, )
Both values can exceed the range of a 64 bit integer.
Output
If you can guarantee a win, print Your wish is granted! on the first line. Otherwise print You will become a flying monkey!. Do not print the quotes.