Triangular Numbers which are also Square

Theorem
Let $A_n$ be the $n$th non-negative integer whose square is also a triangular number.

Then:
 * $A_n = \begin{cases} 0 & : n = 0 \\

1 & : n = 1 \\ 6 A_{n - 1} - A_{n - 2} & : n > 1 \end{cases}$

Proof
Let $n \in \Z_{>0}$ be such that $n^2$ is a triangular number.

Then we have:

This is a Pellian Equation.

From Pell's Equation: $x^2 - 8 y^2 = 1$, the smallest positive integral solution is:
 * $\tuple {x, y} = \tuple {3, 1}$

Thus we have that the sequence of $n$ such that $n^2$ is triangular is the sequence of numerators of the Continued Fraction Expansion of $\sqrt 8$ whose indices are even.

Let $\tuple {x, y} = \tuple {p_k, q_k}$ be a solution to $x^2 - 8 y^2 = 1$.

Then from Continued Fraction Expansion of $\sqrt 8$ we have:

Hence the result.