| Codeforces Round 1093 (Div. 1) |
|---|
| Finished |
Roger has $$$p$$$ unit-length segments and $$$q$$$ L-shaped pieces, each formed by joining two unit-length segments at a right angle.
He wants to use all of these pieces, with no piece left unused, to form a grid of dimensions $$$n \times m$$$.
Given $$$p$$$ and $$$q$$$, determine whether there exist positive integers $$$n$$$ and $$$m$$$ such that an $$$n \times m$$$ grid can be formed using exactly $$$p$$$ unit-length segments and $$$q$$$ L-shaped pieces, possibly rotating them, and provide any valid $$$n$$$ and $$$m$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$p$$$ and $$$q$$$ ($$$1 \le p, q \le 10^8$$$).
For each test case, print any valid $$$n$$$ and $$$m$$$ such that it's possible to construct $$$n \times m$$$ using all pieces. If there are no such $$$n$$$ and $$$m$$$, print $$$-1$$$.
71 21 35 12 52 10100000000 1000000001 1
-11 21 22 22 4-1-1
Here are the constructions for examples 2, 3, and 4. We use a different color for different L-shaped pieces, black for all unit-length segments.
| Name |
|---|


