[Math] Finding the sum of numbers between any two given numbers
arithmetic
I tried to derive this type of formula and ended up with this . But it's not holding true for all the numbers. Can you please tell what I've done wrong !!
Best Answer
Between $\alpha$ and $\beta$, there are $\beta - \alpha + 1$ numbers. We need
\begin{align*}
S &= \alpha + (\alpha + 1) + \cdots + \beta \\
&= \beta + (\beta - 1) +\cdots + \alpha
\end{align*}
Adding vertically, we have
\begin{equation*}
2S = (\beta-\alpha+1)(\alpha+\beta)
\end{equation*}
Hence
\begin{equation*}
S = \frac{(\beta-\alpha+1)(\alpha+\beta)}{2}
\end{equation*}
This "reverse and add" technique is due to Gauss and can be used to sum any arithmetic progression as well.
Apart the possibilities already suggested (use of $mod$ and use of $(-1)^n$, you can also use the floor function
$$
f(n) = 6n+7-2\left\lfloor\frac{n}{2}\right\rfloor
$$
Best Answer
Between $\alpha$ and $\beta$, there are $\beta - \alpha + 1$ numbers. We need \begin{align*} S &= \alpha + (\alpha + 1) + \cdots + \beta \\ &= \beta + (\beta - 1) +\cdots + \alpha \end{align*} Adding vertically, we have \begin{equation*} 2S = (\beta-\alpha+1)(\alpha+\beta) \end{equation*} Hence \begin{equation*} S = \frac{(\beta-\alpha+1)(\alpha+\beta)}{2} \end{equation*} This "reverse and add" technique is due to Gauss and can be used to sum any arithmetic progression as well.