# How many sequences of consecutive integers are there where the sum equals the length

I am really sad and I noticed that the sequence:

$0 , 1 , 2$

Has its sum equal to its length.

I was wondering how many these existed.

e.g:

$1$

$-3 , -2 , -1 , 0 , 1 , 2 , 3 , 4 , 5$ $(= 9)$

I got so far and got stuck, I reduced it down to finding out how many solutions there are to the equation:

$m^2 - n^2 + m + n = 0$ , $0 < n < m$

Can anyone tell me how to find this out?

-

The sum of $0 + 1 + 2 + \ldots + (n-1)$ is $\frac{n(n-1)}{2}$ (and has length $n$) so the sum of any length $n$ sequence of consecutive integers starting at $m$ is $nm + \frac{n(n-1)}{2}$ (since such sequences are of the form $m+0,m+1,m+2,\ldots,m+(n-1)$) and we need to solve the diophantine equation $$nm + \frac{n(n-1)}{2} = n.$$

We should cancel $n$ and double it to get $2m + n = 3.$ This equation will only have solutions for odd $n$, this tells us there are no even length sequences with that property. On the other hand if $n$ is odd, there is exactly one such sequence.

n | m  | 2m+n  | sequence
-------------------------
1 | 1  | 3     | 1
2 | impossible...
3 | 0  | 3     | 0 1 2
4 | impossible...
5 | -1 | 3     | -1 0 1 2 3
6 | impossible...
...

-
Surly there are at least three solutions? –  Robert Nov 9 '12 at 14:47
Robert I believe @spernerslemma is showing you that for any given odd $n$, there is only one such sequence...So there is one and only one sequence when length & sum is 1 (i.e., "1"), when length and sum is 3...etc. –  amWhy Nov 9 '12 at 14:50
@Robert, I've added a table that explains how the solution of the diophantine equation relates to the existence of the sequences. –  sperners lemma Nov 9 '12 at 14:52
Got it... So there are infinitely many solutions –  Robert Nov 9 '12 at 14:57
@GottfriedHelms your solution has $n=11$, not $n=6$ (In the above solution $n$ represents the length of the sequence, not the largest number of the sequence) –  Morgan Sherman Nov 10 '12 at 12:31

The sum of a nonempty sequence of numbers is equal to its length if and only if the average of its terms is $1$. The average of a sequence of consecutive integers is an integer if and only if the length of the sequence is odd, in which case it is the middle term of the sequence. So you are looking at the set of all odd-length sequences of successive integers whose middle term is $1$; these are easy to list, and there are infinitely many of them. Don't forget the empty sequence, which also qualifies.

-

You can factor it as $(m-n+1)(m+n)=0$. The right factor is positive, so you must have $m+1=n$. This violates your last inequality.

However, if you have the numbers running from $-n$ to $m$ the correct expression is $\frac 12(m^2+m) - \frac 12 (n^2+n)=m+n+1$ which yields $m^2-m-n^2-3n-2=0$

-
I decided that there were always going to be more positive terms then negative. I defined n as the first positive term which was greater than the smallest negative number (x-1). M was the last term in the sequence. I might have made a mistake in my algebra... ill check. –  Robert Nov 9 '12 at 14:49