Reply
 
Thread Tools Display Modes
  #1  
Old 08-29-2016, 04:45 PM
HeyHomie HeyHomie is offline
Charter Member
 
Join Date: Sep 1999
Location: Viburnum, MO
Posts: 9,110
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  
Old 08-29-2016, 04:56 PM
Schnitte Schnitte is offline
Intermittently active
 
Join Date: Feb 2001
Location: Frankfurt, Germany
Posts: 3,440
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  
Old 08-29-2016, 04:59 PM
Schnitte Schnitte is offline
Intermittently active
 
Join Date: Feb 2001
Location: Frankfurt, Germany
Posts: 3,440
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  
Old 08-29-2016, 05:03 PM
OldGuy OldGuy is offline
Charter Member
 
Join Date: Dec 2002
Location: Very east of Foggybog, WI
Posts: 4,389
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
  #5  
Old 08-29-2016, 05:05 PM
The Great Unwashed The Great Unwashed is offline
Guest
 
Join Date: Mar 2002
Location: France
Posts: 2,081
For consecutive integers, m... ...n, the formula is

(m+n)(m-n+1)/2
  #6  
Old 08-29-2016, 05:10 PM
Chronos Chronos is offline
Charter Member
Moderator
 
Join Date: Jan 2000
Location: The Land of Cleves
Posts: 72,187
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  
Old 08-29-2016, 05:10 PM
Derleth Derleth is offline
Guest
 
Join Date: Apr 2000
Location: Missoula, Montana, USA
Posts: 19,713
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.
  #8  
Old 08-29-2016, 05:12 PM
HeyHomie HeyHomie is offline
Charter Member
 
Join Date: Sep 1999
Location: Viburnum, MO
Posts: 9,110
Thanks! Having mathematicians around is helpful!
  #9  
Old 08-29-2016, 05:29 PM
Indistinguishable Indistinguishable is online now
Guest
 
Join Date: Apr 2007
Posts: 10,512
Quote:
Originally Posted by Derleth View Post
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.
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".

Last edited by Indistinguishable; 08-29-2016 at 05:34 PM.
  #10  
Old 08-29-2016, 07:32 PM
OldGuy OldGuy is offline
Charter Member
 
Join Date: Dec 2002
Location: Very east of Foggybog, WI
Posts: 4,389
Quote:
Originally Posted by The Great Unwashed View Post
For consecutive integers, m... ...n, the formula is

(m+n)(m-n+1)/2
Be careful with this one. The formula assumes m > n, but the description would imply m < n.
  #11  
Old 08-30-2016, 02:17 AM
The Great Unwashed The Great Unwashed is offline
Guest
 
Join Date: Mar 2002
Location: France
Posts: 2,081
Quote:
Originally Posted by OldGuy View Post
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
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 06:42 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.

Send questions for Cecil Adams to: cecil@chicagoreader.com

Send comments about this website to: webmaster@straightdope.com

Terms of Use / Privacy Policy

Advertise on the Straight Dope!
(Your direct line to thousands of the smartest, hippest people on the planet, plus a few total dipsticks.)

Publishers - interested in subscribing to the Straight Dope?
Write to: sdsubscriptions@chicagoreader.com.

Copyright 2017 Sun-Times Media, LLC.

 
Copyright © 2017