FAQ 
Calendar 


#1




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? 
Advertisements  

#2




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.
__________________
"The banana has certain characteristics, appearance, taste, softness, seedlessness, easy handling, a constant level of production which enable it to satisfy the constant needs of an important section of the population consisting of the very young, the old and the sick." 
#3




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. 
#4




So in summary (pun intended) the formula for the sum of the integers from m to n is
[n*(n+1)m*(m1)]/2 


#5




For consecutive integers, m... ...n, the formula is
(m+n)(mn+1)/2 
#6




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. 
#7




The most general term for the kind of thing you're looking for is "closedform expression" or similar; these problems have no magical solution, but instead require some insight and patternmatching to solve.
Here's a page on the subject which walks you through an example and provides some general advice. 
#8




Thanks! Having mathematicians around is helpful!

#9




Quote:
Last edited by Indistinguishable; 08292016 at 05:34 PM. 


#10




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

#11




Quote:
S = (m+n)(nm+1)/2 
Reply 
Thread Tools  
Display Modes  

