Project Euler Problem 66 Solution

Question

Consider quadratic Diophantine equations of the form:

x2Dy2=1 \begin{aligned} x^2-Dy^2=1 \end{aligned}

For example, when D=13D=13, the minimal solution in xx is 6492131802=16492 - 131802 = 1.

It can be assumed that there are no solutions in positive integers when DD is square.

By finding minimal solutions in xx for D=2,3,5,6,7D = {2, 3, 5, 6, 7}, we obtain the following:

322×22=1223×12=1925×42=1526×22=1827×32=1 \begin{aligned} 3^2 - 2 \times 2^2 &= 1 \\ 2^2 - 3 \times 1^2 &= 1 \\ 9^2 - 5 \times 4^2 &= 1 \\ 5^2 - 6 \times 2^2 &= 1 \\ 8^2 - 7 \times 3^2 &= 1 \\ \end{aligned}

Hence, by considering minimal solutions in xx for D7D \leq 7, the largest xx is obtained when D=5D=5.

Find the value of D1000D \leq 1000 in minimal solutions of xx for which the largest value of xx is obtained.

Haskell