[Math] Check whether or not a triangular number is triangular is the square-sum of two other consecutive triangular numbers

binomial-coefficientsnumber theory

I'm trying to write a program that would tell me whether or not a triangular number, a number of the form $\frac{(n)(n+1)}{2}$ is the sum of the squares of two other consecutive triangular numbers. It is guaranteed that the given $n$ is triangular. On oeis.org it gives a formula two calculate the nth number which satisfies the above, but no where can I find how to check whether or not a number satisfies the above.

I know this may not be the right place to post this, but I wanted a more mathematical answer to this.

Best Answer

$$8\frac{n(n+1)}2+1=\left(2n+1\right)^2.$$ Check if $8m+1$ is a perfect square. (By taking its square root.)


Update:

The question is about numbers that are the sum of two consecutive triangular numbers, i.e. which are of the form

$$m=\left(\frac{(n-1)n}2\right)^2+\left(\frac{n(n+1)}2\right)^2=\frac{n^2(n^2+1)}2.$$

By the above criterion, $$8m+1=(2n^2+1)^2$$ must be a perfect square and its square root $r$ must be such that $\dfrac{r-1}2$ is a perfect square.

In other words,

$$\sqrt{\frac{\sqrt{8m+1}-1}2}\in\mathbb N.$$