CF2219A.Grid L
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 $ .
输入输出样例
输入#1
7 1 2 1 3 5 1 2 5 2 10 100000000 100000000 1 1
输出#1
-1 1 2 1 2 2 2 2 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.

输入解题思路,AI测评打分。不知道怎么写?