Problem AJ
Boastin' Red Socks
You have a drawer that is full of two kinds of socks: red
and black. You know that there are at least
You have noticed, though, that when you reach into the
drawer each morning and choose two socks to wear (in pitch
darkness, so you cannot distinguish red from black), the
probability that you pick two red socks is exactly
From this, can you determine how many socks of each colour are in your drawer? There may be multiple solutions – if so, pick the solution with the fewest total number of socks, but still allowing you to wear a couple of same color socks.
Input
Input consists of multiple problems, each on a separate
line. Each problem consists of the integers
Input is terminated by a line consisting of two zeroes.
Output
For each problem, output a single line consisting of the number of red socks and the number of black socks in your drawer, separated by one space. If there is no solution to the problem, print “impossible”.
Sample Input 1 | Sample Output 1 |
---|---|
1 2 6 8 12 2499550020 56 789 0 0 |
3 1 7 1 4 49992 impossible |