Interestingly for triangular numbers:

$X(X+1)+Y(Y+1)=Z(Z+1)+a$

$a$ - this number is determined by the condition of the problem. Are all numbers equation has a solution? And what kind of formula in general is?