There’s a renowned story that Gauss, mathematician extraordinaire, had actually a lazy teacher. The so-called educator wanted to keep the children busy therefore he could take a nap; that asked the course to include the numbers 1 to 100.
You are watching: Sum of numbers from 1 to 100
Gauss approached through his answer: 5050. Therefore soon? The teacher suspected a cheat, however no. Manual enhancement was because that suckers, and also Gauss discovered a formula come sidestep the problem:
Let’s re-superstructure a couple of explanations that this an outcome and really recognize it intuitively. Because that these examples we’ll include 1 to 10, and also then see how it applies for 1 to 100 (or 1 to any kind of number).
Technique 1: Pair Numbers
Pairing number is a common strategy to this problem. Rather of creating all the number in a solitary column, let’s wrap the number around, choose this:
1 2 3 4 510 9 8 7 6An interesting pattern emerges: the amount of each tower is 11. Together the optimal row increases, the bottom heat decreases, therefore the sum continues to be the same.
Because 1 is paired with 10 (our n), we have the right to say the each column has (n+1). And also how numerous pairs execute we have? Well, we have actually 2 same rows, us must have n/2 pairs.
which is the formula above.
Wait — what about an odd number of items?
Ah, ns glad you lugged it up. What if us are including up the number 1 to 9? us don’t have an even number of items come pair up. Plenty of explanations will certainly just provide the explanation above and leave it at that. Ns won’t.
Let’s add the number 1 to 9, however instead of beginning from 1, let’s counting from 0 instead:
0 1 2 3 49 8 7 6 5By counting indigenous 0, we obtain an “extra item” (10 in total) for this reason we can have one even variety of rows. However, ours formula will certainly look a little bit different.
Notice the each column has actually a amount of n (not n+1, like before), since 0 and also 9 are grouped. And instead of having exactly n items in 2 rows (for n/2 pairs total), we have n + 1 item in 2 rows (for (n + 1)/2 pairs total). If friend plug this numbers in you get:
which is the very same formula together before. It constantly bugged me the the same formula worked for both odd and even numbers – i will not ~ you obtain a fraction? Yep, you acquire the same formula, yet for different reasons.
Technique 2: Use 2 Rows
The above method works, yet you handle odd and also even numbers differently. Isn’t over there a better way? Yes.
Instead that looping the numbers around, let’s compose them in two rows:
1 2 3 4 5 6 7 8 9 1010 9 8 7 6 5 4 3 2 1Notice that we have actually 10 pairs, and also each pair adds up to 10+1.
The complete of every the numbers over is
But we only want the amount of one row, not both. Therefore we divide the formula above by 2 and get:
Now this is cool (as cool as rows that numbers deserve to be). It functions for one odd or even number of items the same!
Technique 3: make a Rectangle
I newly stumbled upon one more explanation, a fresh method to the old pairing explanation. Various explanations work better for different people, and also I have tendency to choose this one better.
Instead of composing out numbers, ~ do so we have beans. We desire to include 1 bean to 2 beans to 3 beans… every the method up come 5 beans.
xx xx x xx x x xx x x x xSure, we could go to 10 or 100 beans, but with 5 you obtain the idea. Just how do us count the number of beans in our pyramid?
Well, the sum is plainly 1 + 2 + 3 + 4 + 5. However let’s look in ~ it a various way. Let’s say we winter our pyramid (I’ll usage “o” for the mirrored beans), and then topple the over:
x o x o o o o ox x o o x x o o o ox x x o o o => x x x o o ox x x x o o o o x x x x o ox x x x x o o o o o x x x x x oCool, huh? In case you’re wondering even if it is it “really” lines up, the does. Take it a look in ~ the bottom row of the continual pyramid, v 5′x (and 1 o). The next row of the pyramid has actually 1 less x (4 total) and 1 an ext o (2 total) to fill the gap. As with the pairing, one next is increasing, and the various other is decreasing.
Now for the explanation: How many beans carry out we have actually total? Well, that’s just the area of the rectangle.
We have actually n rows (we didn’t readjust the variety of rows in the pyramid), and our collection is (n + 1) units wide, because 1 “o” is combine up through all the “x”s.
Notice that this time, us don’t care around n being odd or also – the complete area formula functions out simply fine. If n is odd, we’ll have an even variety of items (n+1) in every row.
But of course, we don’t desire the complete area (the variety of x’s and o’s), we just want the number of x’s. Because we double the x’s to gain the o’s, the x’s through themselves room just fifty percent of the full area:
And we’re back to our initial formula. Again, the variety of x’s in the pyramid = 1 + 2 + 3 + 4 + 5, or the amount from 1 to n.
Technique 4: median it out
We all recognize that
average = amount / number of items
which we deserve to rewrite to
sum = average * variety of items
So let’s figure out the sum. If we have 100 numbers (1…100), then we plainly have 100 items. The was easy.
To gain the average, an alert that the numbers room all same distributed. Because that every big number, yes a little number ~ above the various other end. Let’s look in ~ a small set:
1 2 3The median is 2. 2 is already in the middle, and also 1 and 3 “cancel out” so their typical is 2.
For one even number of items
1 2 3 4the average is between 2 and also 3 – it’s 2.5. Also though we have actually a fractional average, this is yes — since we have actually an even number of items, once we multiply the typical by the count that ugly fraction will disappear.
Notice in both cases, 1 is on one next of the average and also N is equally far away on the other. So, we deserve to say the median of the entire collection is actually just the typical of 1 and n: (1 + n)/2.
Putting this into our formula
And voila! We have actually a fourth way of thinking about our formula.
So why is this useful?
1) including up numbers easily can be advantageous for estimation. An alert that the formula broadens to this:
Let’s speak you want to include the numbers from 1 come 1000: intend you acquire 1 additional visitor to your website each day – just how many complete visitors will you have after 1000 days? since thousand squared = 1 million, we gain million / 2 + 1000/2 = 500,500.
2) This concept of including numbers 1 to N shows up in various other places, favor figuring the end the probability for the birthday paradox. Having a firm master of this formula will aid your knowledge in plenty of areas.
3) many importantly, this instance shows over there are numerous ways to know a formula. Maybe you prefer the pairing method, maybe you like the rectangle technique, or possibly there’s one more explanation that works for you. Don’t give up as soon as you don’t recognize — shot to find an additional explanation that works. Happy math.
By the way, there are an ext details around the background of this story and the method Gauss may have actually used.
Instead that 1 come n, how about 5 come n?
Start v the constant formula (1 + 2 + 3 + … + n = n * (n + 1) / 2) and also subtract turn off the component you don’t want (1 + 2 + 3 + 4 = 4 * (4 + 1) / 2 = 10).
Sum for 5 + 6 + 7 + 8 + … n =
Sum native a to n =
See more: What Wii Consoles Can A Wii Play Gamecube Games, Can'T Play Gamecube Games On The Wii Console
How about even numbers, prefer 2 + 4 + 6 + 8 + … + n?
Just double the consistent formula. To add evens native 2 to 50, discover 1 + 2 + 3 + 4 … + 25 and dual it:
Sum of 2 + 4 + 6 + … + n = 2 * (1 + 2 + 3 + … + n/2) = 2 * n/2 * (n/2 + 1) / 2 = n/2 * (n/2 + 1)So, to get the evens from 2 come 50 you’d perform 25 * (25 + 1) = 650
How about odd numbers, choose 1 + 3 + 5 + 7 + … + n?
That’s the same as the also formula, except each number is 1 much less than its equivalent (we have 1 rather of 2, 3 rather of 4, and also so on). We gain the following biggest even number (n + 1) and take off the extra (n + 1)/2 “-1″ items:
Sum that 1 + 3 + 5 + 7 + … + n = <(n + 1)/2 * ((n + 1)/2 + 1)> – <(n + 1) / 2>To include 1 + 3 + 5 + … 13, obtain the next biggest even (n + 1 = 14) and do
<14/2 * (14/2 + 1)> – 7 = 7 * 8 – 7 = 56 – 7 = 49Combinations: evens and also offset
Let’s to speak you desire the evens native 50 + 52 + 54 + 56 + … 100. Uncover all the evens
2 + 4 + 6 + … + 100 = 50 * 51and subtract off the ones you nothing want
2 + 4 + 6 + … 48 = 24 * 25So, the amount from 50 + 52 + … 100 = (50 * 51) – (24 * 25) = 1950
Phew! hope this helps.
Ruby nerds: you can examine this using
<...Array(51).keys()>.map(x => x + 50).filter(x => x % 2 == 0).reduce((x, y) => x + y)1950// Note: There space 51 numbers from 50-100, inclusive. Fencepost!