There’s a famous story the Gauss, mathematician extraordinaire, had a lazy teacher. The so-called educator want to keep the children busy so he might take a nap; that asked the course to add the numbers 1 come 100.

You are watching: What is the sum of numbers from 1 to 100

Gauss approached through his answer: 5050. For this reason soon? The teacher suspected a cheat, yet no. Manual enhancement was because that suckers, and also Gauss found a formula to sidestep the problem:  Let’s re-publishing a few explanations that this an outcome and really understand it intuitively. For these instances we’ll add 1 come 10, and also then see exactly how it uses for 1 to 100 (or 1 to any number).

## Technique 1: Pair Numbers

Pairing number is a common technique to this problem. Rather of composing all the number in a solitary column, stop wrap the numbers around, favor this:

1 2 3 4 510 9 8 7 6An amazing pattern emerges: the sum of each tower is 11. As the top row increases, the bottom heat decreases, therefore the sum stays the same.

Because 1 is paired through 10 (our n), we have the right to say that each column has (n+1). And also how many pairs execute we have? Well, we have actually 2 equal rows, we must have n/2 pairs. which is the formula above.

## Wait — what about an odd number of items?

Ah, i’m glad you brought it up. What if we are adding up the number 1 to 9? we don’t have an even number of items to pair up. Numerous explanations will certainly just give the explanation above and leave it at that. Ns won’t.

Let’s add the numbers 1 come 9, yet instead of beginning from 1, let’s count from 0 instead:

0 1 2 3 49 8 7 6 5By counting native 0, we gain an “extra item” (10 in total) for this reason we have the right to have one even variety of rows. However, our formula will look a bit different.

Notice the each column has actually a sum of n (not n+1, favor before), due to the fact that 0 and 9 are grouped. And also instead the having precisely n item in 2 rows (for n/2 bag total), we have actually n + 1 items in 2 rows (for (n + 1)/2 bag total). If girlfriend plug these numbers in friend get: which is the exact same formula together before. It constantly bugged me that the very same formula operated for both odd and even numbers – i will not ~ you gain a fraction? Yep, you obtain the exact same formula, however for different reasons.

## Technique 2: Use two Rows

The above an approach works, however you manage odd and also even numbers differently. Isn’t over there a far better way? Yes.

Instead the looping the numbers around, let’s write 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 10 pairs, and each pair adds approximately 10+1.

The complete of every the numbers above is But we just want the amount of one row, no both. For this reason we divide the formula above by 2 and get: Now this is cool (as cool as rows the numbers can be). It functions for an odd or even number of items the same!

## Technique 3: do a Rectangle

I freshly stumbled upon an additional explanation, a fresh method to the old pairing explanation. Various explanations work better for different people, and I have tendency to like this one better.

Instead of composing out numbers, pretend we have beans. We desire to include 1 p to 2 beans to 3 beans… every the way up to 5 beans.

xx xx x xx x x xx x x x xSure, we might go to 10 or 100 beans, however with 5 you gain the idea. Exactly how do we count the variety of beans in our pyramid?

Well, the sum is clearly 1 + 2 + 3 + 4 + 5. However let’s look in ~ it a various way. Let’s say we mirror our pyramid (I’ll usage “o” because that the copy 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 whether it “really” lines up, that does. Take a look at the bottom row of the continuous pyramid, through 5′x (and 1 o). The following row that the pyramid has actually 1 less x (4 total) and 1 an ext o (2 total) to to fill the gap. Just like the pairing, one next is increasing, and the other is decreasing.

Now because that the explanation: How plenty of beans do we have total? Well, that’s just the area the the rectangle.

We have actually n rows (we didn’t adjust the number of rows in the pyramid), and our repertoire is (n + 1) units wide, because 1 “o” is paired up with all the “x”s. Notice the this time, we don’t care around n gift odd or even – the total area formula works out simply fine. If n is odd, we’ll have actually an even variety of items (n+1) in every row.

But of course, we don’t want the complete area (the variety of x’s and o’s), we simply want the number of x’s. Because we doubled the x’s to acquire the o’s, the x’s through themselves space just fifty percent of the complete area: And we’re back to our original formula. Again, the variety of x’s in the pyramid = 1 + 2 + 3 + 4 + 5, or the sum from 1 to n.

## Technique 4: median it out

We all understand that

average = amount / number of items

which we have the right to rewrite to

sum = average * number 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 get the average, an alert that the numbers space all same distributed. Because that every large number, yes a little number top top the other end. Let’s look in ~ a tiny set:

1 2 3The median is 2. 2 is currently in the middle, and 1 and also 3 “cancel out” so their mean is 2.

For an even number of items

1 2 3 4the typical is in between 2 and 3 – the 2.5. Even though we have a fountain average, this is yes — since we have actually an even number of items, when we main point the typical by the count that ugly portion will disappear.

Notice in both cases, 1 is ~ above one next of the average and N is equally much away on the other. So, we have the right to say the mean of the entire collection is actually simply the typical of 1 and also n: (1 + n)/2.

Putting this into our formula And voila! We have a fourth way of thinking around our formula.

## So why is this useful?

Three reasons:

1) adding up numbers easily can be advantageous for estimation. An alert that the formula increases to this: Let’s to speak you want to add the numbers from 1 to 1000: expect you acquire 1 extr visitor come your site each job – exactly how many full visitors will you have actually after 1000 days? since thousand squared = 1 million, we acquire million / 2 + 1000/2 = 500,500.

2) This concept of including numbers 1 to N shows up in other places, prefer figuring out the probability because that the date of birth paradox. Having actually a firm grasp of this formula will assist your understanding in many areas.

3) many importantly, this instance shows there are countless ways to recognize a formula. Possibly you choose the pairing method, perhaps you choose the rectangle technique, or perhaps there’s an additional explanation that works for you. Don’t give up once you don’t recognize — shot to find an additional explanation the works. Happy math.

By the way, there are much more details about the history of this story and also the method Gauss may have used.

## Variations

Instead of 1 to n, how around 5 come n?

Start v the continual formula (1 + 2 + 3 + … + n = n * (n + 1) / 2) and also subtract turn off the component you don’t desire (1 + 2 + 3 + 4 = 4 * (4 + 1) / 2 = 10).

Sum because that 5 + 6 + 7 + 8 + … n = – 10And because that any beginning number a:

Sum from a come n = – <(a - 1) * a / 2>We want to remove every number indigenous 1 approximately a – 1.

See more: Why Does Tom Hanks Hand Shake, Does Tom Hanks Have Parkinson'S

How about even numbers, favor 2 + 4 + 6 + 8 + … + n?

Just double the regular formula. To include evens indigenous 2 to 50, uncover 1 + 2 + 3 + 4 … + 25 and twin 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 obtain the evens from 2 to 50 you’d execute 25 * (25 + 1) = 650

How about odd numbers, like 1 + 3 + 5 + 7 + … + n?

That’s the very same as the also formula, except each number is 1 much less than its counterpart (we have 1 instead of 2, 3 rather of 4, and also so on). We obtain the following biggest even number (n + 1) and also take off the extra (n + 1)/2 “-1″ items:

Sum the 1 + 3 + 5 + 7 + … + n = <(n + 1)/2 * ((n + 1)/2 + 1)> – <(n + 1) / 2>To add 1 + 3 + 5 + … 13, acquire the next biggest also (n + 1 = 14) and also 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. Discover all the evens

2 + 4 + 6 + … + 100 = 50 * 51and subtract off the people you don’t want

2 + 4 + 6 + … 48 = 24 * 25So, the sum from 50 + 52 + … 100 = (50 * 51) – (24 * 25) = 1950

Phew! expect this helps.

Ruby nerds: you can inspect this using

(50..100).select x.inject(:+)1950Javascript geeks, execute this:

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