# Gauss formula to add number of sequence for arbitrary range

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?

• Hint: add numbers 1-30, 1-2, subtract. – dxiv Sep 7 '16 at 4:56

## 2 Answers

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

• Thanks, i think it is (a+b)(b-a+1)/2 ? – user1767754 Sep 7 '16 at 5:03
• Yes. Thank you. – Rafael Holanda Sep 7 '16 at 5:04

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.