#P5779. Deduce the Hidden Numbers from Rounds of Inference
Deduce the Hidden Numbers from Rounds of Inference
Deduce the Hidden Numbers from Rounds of Inference
A logic professor has three exceptionally sharp students named A, B, and C. One day, he sticks a paper with a positive integer on each student’s forehead and announces that for these three numbers one of them is the sum of the other two. Each student can see the numbers on the other two students but not their own.
The professor then begins repeatedly asking the students (in the order A, then B, then C, and so on) if they can deduce the number on their own forehead. In every round before someone makes a correct guess, every student answers, "I cannot deduce my number." Eventually, on the professor's Nth question, the student with the largest number (which, as you may prove, is always the first to be sure) suddenly smiles and correctly announces his own number, M.
Your task is: Given the round number N when the announcement was made and the value M of the largest number, deduce the other two numbers on the remaining students' foreheads.
Explanation: Let the three numbers be x, y, and M, where M is the largest and it holds that M = x + y. A detailed logical analysis shows that the student with the largest number will be able to deduce his own number exactly on the round equal to the smaller of the other two numbers. That is, if we denote the smaller of x and y by N, then it must be that x = N and y = M - N. You may assume that the input always satisfies 2*N ≤ M so that the deduction is valid.
inputFormat
The input consists of two positive integers N and M separated by a space, where:
- N is the round number on which the student with the largest number deduces and announces his number.
- M is the value on the forehead of the student with the largest number.
You may assume that 2 * N ≤ M.
outputFormat
Output two positive integers separated by a space: the two numbers on the other students' foreheads. It is known that if we denote the smaller number by N, then the other number is M - N. The output should list the two numbers in non-decreasing order.
sample
1 3
1 2