# 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

The sum of the natural numbers from $a$ to $b$ inclusive is $$\frac{(a+b)(b-a+1)}{2}.$$
$\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}$