Jack and Jill and Joe
Time limit3sMemory limit512 MB
Find integers a and b with 100 <= a, b <= N maximizing a^2 + b(b+a) subject to |a^2 - b(b+a)| <= 30.
- Level
Medium7 of 10
- Topics
- Number theory, Math, Brute force, Binary search
- Solved
- No attempts yet
Problem
Jill and Jack each buy one plot of land. Jill's plot is a square with side length . Jack's plot is a rectangle whose sides are and , so its longer side exceeds its shorter side by exactly the side length of Jill's square.
Their father Joe sets the following rules.
- and are integers, measured in feet.
- and . The longer side of Jack's plot is not limited by .
- The square of the difference of the two areas is at most 900 square feet, that is .
- Among all pairs that satisfy the rules above, the sum of the two areas is as large as possible.
Find that pair . The pair that maximizes the sum is always unique.
Input
The first line contains the number of test cases . Each of the next lines contains one integer .
Constraints
Output
Print one line for each test case. If no pair satisfies the rules, print impossible. Otherwise print and separated by one space, where is the side length of Jill's square and is the shorter side of Jack's rectangle.