I Need A Formula (Or A Calculator Function) For Adding A Series Of Consecutive Integers

I want to calculate the sum of the numbers 1+2+3+4 and so on. Is there a formula I can use? Does it work with any beginning and ending number (say, 23+24+25 and so on, up to, say 48)?

Is there a quick & easy way to do it on the calculator that came with my iPhone 4S?

You can use the trick used by Gauss in a famous anecdote: You take the largest number in your series, add 1, and multiply that by half the number of integers in your series.

For instance (in Gauss’ example), 1 + 2 + 3 + … + 100 = (1 + 100) * (100/2) = 101 * 50 = 5050. It works because the lowest and the highest number can be paired to 1 + 100; the second lowest and second highest number to 2 + 99, also 101, and so on; you get 50 pairs, all adding up to 101.

Oh, and for your example with 23 + 24 + … + 48: You can apply the trick twice:

First step: Use that method to calculate the sum of all integers up to 48, which is 49 * 24 = 1,176.

Second step: Use the method to calculate the sum of all integers up to 22, which is 12 * 11 = 242.

Third step: Subtract the sum of the integers up to (and including) 22 from the sum of all integers up to and including 48; the difference, 934, is the number you’re looking for.

So in summary (pun intended) the formula for the sum of the integers from m to n is

[n*(n+1)-m*(m-1)]/2

For consecutive integers, m… …n, the formula is

(m+n)(m-n+1)/2

Another way of thinking of it: Take the average of the numbers (which, for consecutive integers, will just be the smallest plus the largest divided by two), and multiply it by the number of them.

Which of course will give you the same result as the other method.

The most general term for the kind of thing you’re looking for is “closed-form expression” or similar; these problems have no magical solution, but instead require some insight and pattern-matching to solve.

Here’s a page on the subject which walks you through an example and provides some general advice.

Thanks! Having mathematicians around is helpful!

In the greatest generality, any particular problem becomes the entirety of human knowledge and ignorance, every solved and unsolved potential problem agglomerated together into “How do I figure out everything?”. But at least the OP’s specific question does indeed have a “magical solution”.

Be careful with this one. The formula assumes m > n, but the description would imply m < n.

Good call.

S = (m+n)(n-m+1)/2