The Game
Time limit1sMemory limit128 MB
Given N and a count M of 'I don't know' answers, find all pairs the master could have chosen in the sum-product guessing game.
- Level
Medium7 of 10
- Topics
- Simulation, Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
There is a legend that in the 18th century mathematicians enjoyed the following game.
Three mathematicians take part, and one of them is the game master. The game master first announces a positive integer . He then secretly chooses two different integers and , each between and inclusive, and privately tells their sum to player and their product to player . Each player learns only their own value and knows whether it is the sum or the product.
The two players then speak in turns, always in the fixed order , , , , — player always speaks first. On each turn the current player announces either "I know these numbers" or "I don't know these numbers", reasoning only from their own value and from every statement made so far (all statements are public). A player can name the pair exactly when only one pair is still consistent with everything known. The game ends the instant a player says "I know".
For example, the dialog might go like this:
- Game master: "Let be ." (then he chooses two numbers from to and tells their sum to and their product to )
- Player : "I don't know these numbers."
- Player : "I don't know these numbers."
- Player : "I don't know these numbers."
- Player : "I don't know these numbers."
- Player : "Now I know these numbers — you chose and ."
You are given and , where is the total number of times "I don't know these numbers" was said before the game ended (so the final "I know" is statement number ). Find every pair of numbers the game master could have chosen.
Input
One line with two integers and (, ).
Output
On the first line, print the number of pairs the game master could have chosen from to so that the players said "I don't know these numbers" exactly times before someone said "I know".
Then print those pairs, one per line, each as two integers " " with . Print the pairs in ascending order: sorted by the first number, and by the second number when the first numbers are equal.