#3275. PELL2 - Pell (Mid pelling)
PELL2 - Pell (Mid pelling)
PELL2 - Pell (Mid pelling)
题面翻译
题目描述
给定 ,求方程 的最小正整数解。
请注意,方程可能有解,也可能无解。 例如: 当 时,,有解 和 。 当 时,,有解 和 。 当 时,无解。
输入输出格式
输入格式: 第一行输入一个整数 ,代表数据组数,对于每组数据,仅一行一个整数为给定 的值。
输出格式: 对于每组数据,如果有解,输出 和 的解;若无解,输出 -1
。
题目描述
D is a given positive integer, consider the equation : X² = D×Y² + 1, with X and Y positive integers. Find the minimum numbers (X,Y) within all solutions. Sometimes it's possible, sometimes not!
Examples : If D=2, 3² = 2×2² + 1, so X=3 and Y=2. If D=3, 2² = 3×1² + 1, so X=2 and Y=1. If D=4, it's impossible!
输入格式
The input begins with the number T of test cases in a single line. In each of the next T lines there is one integer D.
输出格式
For each test case, if possible print X and Y the answer of the problem for D, else "-1".
样例 #1
样例输入 #1
3
2
3
4
样例输出 #1
3 2
2 1
-1
提示
T <= 1000 1 < D <= 10^7, the numbers D were randomly chosen.