# Find general solution for the equation $1 + 2 + \cdots + (n − 1) = (n + 1) + (n + 2) + \cdots + (n + r)$

A positive integer $n$ is called a balancing number if

$$1 + 2 + \cdots + (n − 1) = (n + 1) + (n + 2) + \cdots + (n + r) \tag{1}$$

for some positive integer $r$.

Problem: Find the general solution (closed-form expression) of equation $(1)$, in other words, find $f_1(m)=n, f_2(m)=r$ where $f_1, f_2$ are solution of $(1)$ for any integer $m \in \mathbb Z$.

I have asked a similar question with a constrain involving Pell’s equation.

#### Solutions Collecting From Web of "Find general solution for the equation $1 + 2 + \cdots + (n − 1) = (n + 1) + (n + 2) + \cdots + (n + r)$"

this question has been repeated quite a bit lately. Here is where these numbers were introduced, in 1999, in The Fibonacci Quarterly. Notice how they say $n$ is such a number if and only if $\sqrt {8n^2 +1}$ is a square. It is not on this page, but the simplest description for isolating $n$ is
the degree two linear recurrence,
$$n_{j+2} = 6 n_{j+1} – n_j,$$
which means you can write $n_j$ as $A \lambda_1^j + B \lambda_2^j,$ with real constants $A,B$ and the lambdas are the two roots of
$$\lambda^2 – 6 \lambda + 1 = 0.$$ Alright,
$$n_j = A \left( 3 + \sqrt 8 \right)^j + B \left( 3 – \sqrt 8 \right)^j$$
with $n_0 = 1, n_1 = 6, n_2 = 35,$ and so on.

Alright, calculated, more convenient to absorb numbers into changing the exponent to $j+1,$ so I get

$$\color{blue}{ n_j = \frac{1}{2 \sqrt 8} \left( \left( 3 + \sqrt 8 \right)^{j+1} – \left( 3 – \sqrt 8 \right)^{j+1} \right)}$$
Yep, works for $j = 0$ and $j = 1.$

Let us name $w_j = \sqrt{ 8 n_j^2 + 1},$
$$\color{blue}{ w_j = \sqrt{ 8 n_j^2 + 1} = \frac{1}{2 } \left( \left( 3 + \sqrt 8 \right)^{j+1} + \left( 3 – \sqrt 8 \right)^{j+1} \right)}$$

We also get
$$w_{j+2} = 6 w_{j+1} – w_j.$$

My memory was not completely wrong, I solved this exact problem last Wednesday, posted it somewhere on MSE. Meanwhile, here is enough information to reconstruct everything. The linear recurrence comes from applying Cayley-Hamilton to the “automorphism matrix” below

 jagy@phobeusjunior:~$./Pell_Target_Fundamental Automorphism matrix: 3 8 1 3 Automorphism backwards: 3 -8 -1 3 3^2 - 8 1^2 = 1 w_j^2 - 8 n_j^2 = 1 Tue Jul 19 12:21:37 PDT 2016 w_j: 3 n_j: 1 ratio: 3 SEED BACK ONE STEP 1 , 0 w_j: 17 n_j: 6 ratio: 2.83333 w_j: 99 n_j: 35 ratio: 2.82857 w_j: 577 n_j: 204 ratio: 2.82843 w_j: 3363 n_j: 1189 ratio: 2.82843 w_j: 19601 n_j: 6930 ratio: 2.82843 w_j: 114243 n_j: 40391 ratio: 2.82843 w_j: 665857 n_j: 235416 ratio: 2.82843 w_j: 3880899 n_j: 1372105 ratio: 2.82843 w_j: 22619537 n_j: 7997214 ratio: 2.82843 Tue Jul 19 12:22:17 PDT 2016 w_j^2 - 8 n_j^2 = 1 jagy@phobeusjunior:~$


$$S=\sum_{k=1}^{n-1}k$$
$$S_1=\sum_{k=1}^r(n+k)$$
the solution of the problem is given by:
$S-S_1=0$ anfd you get:
$$n=r+\dfrac{1}{2}+\dfrac{1}{2}\sqrt{(8r^2+8r+1)}$$
or:
$$n=r+\dfrac{1}{2}-\dfrac{1}{2}\sqrt{(8r^2+8r+1)}$$

As in the other answer, $n = r + 1/2 + 1/2 \cdot \sqrt{2(2r+1)^2-1}$. For $n$ to be an integer we need $t^2 = 2(2r+1)^2-1$ for some odd $t$. The solutions of $t^2-2u^2=-1$ are parameterized by $t+u\sqrt{2} = (1+\sqrt{2})^n$ for odd integers $n$ and will necessarily have $t,u$ odd (examine it mod 8). So for any such $t+u\sqrt{2}$, set $r = (u-1)/2$ and $n = (u-1)/2 + (t+1)/2$