#3275. PELL2 - Pell (Mid pelling)

PELL2 - Pell (Mid pelling)

PELL2 - Pell (Mid pelling)

题面翻译

题目描述

给定 dd,求方程 x2=dy2+1x^2=dy^2+1 的最小正整数解。

请注意,方程可能有解,也可能无解。 例如: 当 d=2d=2 时,32=2×22+13^2= 2 \times 2^2+ 1,有解 x=3x = 3y=2y = 2。 当 d=3d=3 时,22=3×12+12^2= 3 \times 1^2+ 1,有解 x=2x = 2y=1y = 1。 当 d=4d=4 时,无解。

输入输出格式

输入格式: 第一行输入一个整数 TT,代表数据组数,对于每组数据,仅一行一个整数为给定 dd 的值。

输出格式: 对于每组数据,如果有解,输出 xxyy 的解;若无解,输出 -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.