Gauss formula to add number of sequence for arbitrary range

3.3k Views Asked by At

Gauss formula to add numbers from $1-100$ is:

$$ \frac{n(n+1)}{2}$$

How can this be made applicable for arbitrary range, lets say $3-30$? Is there an easy way of doing that rather then linearly adding the numbers up?

2

There are 2 best solutions below

2
On BEST ANSWER

The sum of the natural numbers from $a$ to $b$ inclusive is $$\frac{(a+b)(b-a+1)}{2}.$$

0
On

As a quick guideline and/or explanation of how to get the answer, consider adding the sequence to itself in reverse order:

$\begin{eqnarray} 2S_n & = & S_n + S_n \\ & = & a & + (a + d) & + \ldots & + (a + (n-1)d) & + (a + (n-1)d) & + \ldots & + (a + d) & + a \\ & = & a & + (a + d) & + \ldots & + (a + (n-1)d) \\ & + & (a + (n-1)d) & + (a + (n-2)d) & + \ldots & + a \\ & = & (2a + (n-1)d) & + (2a + (n-1)d) & + \ldots & + (2a + (n-1)d) \\ & = & n(2a + (n-1)d) \\ \therefore S_n & = & \frac{n}{2}(2a + (n-1)d)\end{eqnarray}$

which you can rearrange to give the alternative form.