How to calculate the sum of the integers from $m$ to $n$?
Is this correct?
$$ \frac{n (n+1)}{2} - \frac{m (m+1)}{2}$$
How to calculate the sum of the integers from $m$ to $n$?
Is this correct?
$$ \frac{n (n+1)}{2} - \frac{m (m+1)}{2}$$
On
This is a special of the sum of consecutive terms of an arithmetic progression $(a_n)$: such a sum is equal to the arithmetic mean of the first and the last terms, multiplied by the number of terms:
$$a_m+a_{m+1}+\dots+a_n=\frac{a_m+a_n}2(n-m+1).$$
In the present case, you obtain
$$m+(m+1)+\dots+n=\frac{m+n}2 (n-m+1).$$
Assuming $m\le n$, you are rather subtracting the sum from $0$ to $m-1$ to the sum from $0$ to $n$, so $\frac{n(n+1)}{2}-\frac{m(m-1)}{2}=\frac{(m-n+1)(m+n)}2$. This "incidentally" works when $m<0$ or $n\le0$ as well.