For what values of $n$ is $n(n+2)$ a triangle number?

You are trying to solve $n(n+2)=\frac{m(m+1)}{2}$. This can be written as $(n+1)^2-1 =\frac{(2m+1)^2-1}{8}$, or:

$$(2m+1)^2-8(n+1)^2 = -7$$

The equation $x^2-8y^2=-7$ is called a Pell-like equation, and, since it has the solution $(x,y)=(1,1)$, it has infinitely many solutions. Specifically, if $(x,y)$ is a solution, $(3x+8y,3y+x)$ is a solution. This gives all solutions starting at $(x,y)=(1,1)$ and $(x,y)=(5,2)$.

All solutions for the Pell-like have $x$ odd, so this will always give you a pair $(m,n)$.

The formulas for the values $n+1$ is:

$$n+1=\frac{1}{2\sqrt{8}}\left((1+\sqrt{8})(3+\sqrt{8})^k -(1-\sqrt{8})(3-\sqrt{8})^k\right)$$

and

$$n+1=\frac{1}{2\sqrt{8}}\left((5+2\sqrt{8})(3+\sqrt{8})^k -(5-2\sqrt{8})(3-\sqrt{8})^k\right)$$

That's a horrible expression, but it indicates you an also find a closed formula for the sum of the first $n$. There is also a linear recursion for the sequence of these values of $n$.


Rather than looking at a direct solution to find $n$ values, you can look for a solution to find m values and using which you can find the values of $n$ respectively.

The m values can be seen to follow a dynamic programming pattern, if you look for it. For help, you can look at oeis link (A006451).

To get the values of $n$ from the $m$ values, we can simply use the formulae for solving the quadratic equation and write n as $$ n = \sqrt{\bigg(\frac{y^2 + y +2}2\bigg)} - 1 $$