Given a triangular tower of bricks where the bottom row has $N$ bricks, the next row has $N-1$ bricks, etc, we can ask the question: For which $N$ does there exist a smaller tower with $M \lt N$ bricks (somewhere above the bottom row) such that the number of bricks in the $M$ tower is half the bricks in the $N$ tower?
The Diophantine equation to solve here is:$$N(N+1)=2M(M+1)$$
and the first few solutions are $(N,M)$:
$(3,2)$
$(20,14)$
$(119,84)$
$(696,492)$
Searching OEIS for the $M$ solutions we find it here. In the Formula section of that link it gives the generating function of this sequence as: $$ M(k)=\frac{1}{8}\left(-4+(2+\sqrt{2})(3+2\sqrt{2})^k +(2-\sqrt{2})(3-2\sqrt{2})^k\right) $$ My question is: How in the world was this generating function arrived at?
It seems incredible to me that a closed formula exists for this Diophantine equation. Is this always the case?
EDIT
As @Sil pointed out in a comment, the formula at the OEIS link is not a generating function, but a closed formula. My question though, is basically the same. How was this closed formula arrived at?