Problem Description
For a given positive integer n, please find the smallest positive integer x that we can find an integer y such that y^2 = n +x^2.
Input
The first line is an integer T, which is the the number of cases.
Then T line followed each containing an integer n (1<=n <= 10^9).
Output
For each integer n, please print output the x in a single line, if x does not exit , print -1 instead.
Sample Input
2
2
3
Sample Output
-1
1
我们可以设x = a,y = a + m
则(a + m) ^ 2 = n + a ^ 2
开出来后化简得m ^ 2 + 2 * a * m = n
只需枚举m,并判断a是否为小数
如果a是整数就输出
当m^2 > n时
就可以不用搜了直接输出-1
时间复杂度为O(根号n)
需要我贴代码吗?