Pell Equation Solver
This calculator solves the Pell equation \[x^2 - ny^2=1 \] where $n$ is a nonsquare positive integer. The calculator firstly finds the regular continued fraction $[a_0;a_1,a_2,\ldots]$ of $\sqrt{n}$ using continued fractions calculator and then calculate the sequence of convergents $p_k/q_k$ until they satisfy the equation above. This is the fundamental solution $(x_1,y_1)$. As the Pell equation has many solutions all remaining solutions may be calculated from the relation \[ x_m+y_m\sqrt{n} = (x_1+y_1\sqrt{n})^m \] by expanding the right side, equating coefficients of $\sqrt{n}$ on both sides, and equating the other terms on both sides. For example, the fundamental solution of \[x^2-7y^2=1\] is $(x_1,y_1)=(8,3)$. We calculate the solution $(x_2,y_2)$ from \[ x_2+y_2\sqrt{7} = (8+3\sqrt{7})^2 = 8^2 + 48\sqrt{7}+ (3\sqrt{7})^2 = 127+48\sqrt{7} \] so we have $(x_2,y_2)=(127,48)$ as another solution.