There’s a famous story the Gauss, mathematician extraordinaire, had actually a lazy teacher. The so-called educator wanted to keep the children busy therefore he might take a nap; he asked the class to include the number 1 come 100.

You are watching: Sum of numbers 1-100

Gauss approached with his answer: 5050. Therefore soon? The teacher doubt a cheat, but no. Manual addition was because that suckers, and also Gauss found a formula come sidestep the problem:

Let’s share a few explanations of this an outcome and really recognize it intuitively. Because that these examples we’ll add 1 come 10, and then see just how it uses for 1 come 100 (or 1 to any type of number).

## Technique 1: Pair Numbers

Pairing numbers is a common strategy to this problem. Instead of composing all the numbers in a solitary column, let’s wrap the numbers around, favor this:

1 2 3 4 510 9 8 7 6An interesting pattern emerges: the sum of each tower is 11. Together the optimal row increases, the bottom row decreases, for this reason the sum remains the same.

Because 1 is paired through 10 (our n), we deserve to say that each column has actually (n+1). And how numerous pairs carry out we have? Well, we have actually 2 same rows, we must have n/2 pairs.

which is the formula above.

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

Ah, i’m glad you carried it up. What if us are adding up the numbers 1 come 9? us don’t have an even variety of items come pair up. Numerous explanations will certainly just provide the explanation over and leave it in ~ that. Ns won’t.

Let’s add the number 1 come 9, but instead of starting 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) so we deserve to have one even number of rows. However, our formula will look a little bit different.

Notice that each column has a sum of n (not n+1, choose before), because 0 and also 9 space grouped. And also instead the having precisely n items in 2 rows (for n/2 bag total), we have n + 1 items in 2 rows (for (n + 1)/2 pairs total). If girlfriend plug these numbers in you get:

which is the very same formula together before. It constantly bugged me that the very same formula functioned for both odd and even number – won’t you get a fraction? Yep, you get the same formula, yet for different reasons.

## Technique 2: Use two Rows

The above an approach works, but you manage odd and also even number differently. Isn’t there a far 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 the we have 10 pairs, and also each pair adds as much as 10+1.

The full of every the numbers over is

But we just want the sum of one row, not both. For this reason we division the formula over by 2 and also get:

Now this is cool (as cool together rows of numbers have the right to be). It works for an odd or even number of items the same!

## Technique 3: do a Rectangle

I recently stumbled upon another explanation, a fresh method to the old pairing explanation. Various explanations work much better for different people, and I have tendency to choose this one better.

Instead of creating out numbers, pretend we have actually beans. We desire to add 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 come 10 or 100 beans, yet with 5 you obtain the idea. Exactly how do us count the number of beans in ours pyramid?

Well, the amount is clearly 1 + 2 + 3 + 4 + 5. But let’s look in ~ it a different way. Let’s say we mirror our pyramid (I’ll use “o” because that the mirrored beans), and also 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 instance you’re wondering even if it is it “really” currently up, it does. Take it a look in ~ the bottom row of the consistent pyramid, with 5′x (and 1 o). The next row of the pyramid has 1 less x (4 total) and 1 more o (2 total) to to fill the gap. Similar to the pairing, one side is increasing, and also the other is decreasing.

Now for the explanation: How countless beans perform we have actually total? Well, that’s simply the area that the rectangle.

We have n rows (we didn’t adjust the variety of rows in the pyramid), and our collection is (n + 1) devices wide, since 1 “o” is paired up through all the “x”s.

Notice that this time, us don’t care around n being odd or also – the full area formula functions out simply fine. If n is odd, we’ll have actually an even number of items (n+1) in every row.

But that course, us don’t desire the complete area (the variety of x’s and o’s), we just want the number of x’s. Due to the fact that we double the x’s to acquire the o’s, the x’s through themselves space just fifty percent of the total area:

And we’re ago to our initial formula. Again, the variety of x’s in the pyramid = 1 + 2 + 3 + 4 + 5, or the amount from 1 come n.

## Technique 4: typical it out

We all know that

average = sum / number of items

which we can rewrite to

sum = average * number of items

So let’s number out the sum. If we have 100 number (1…100), then we clearly have 100 items. The was easy.

To gain the average, notification that the numbers are all same distributed. For every big number, there’s a tiny number on the various other end. Stop look in ~ a small set:

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

For one even variety of items

1 2 3 4the typical is in between 2 and 3 – that 2.5. Even though we have actually a fountain average, this is ok — due to the fact that we have actually an even variety of items, once we main point the average by the count the ugly fraction will disappear.

Notice in both cases, 1 is top top one side of the average and also N is equally far away top top the other. So, we have the right to say the mean of the entire collection is actually just the typical of 1 and also n: (1 + n)/2.

Putting this right into our formula

And voila! We have a fourth method of thinking around our formula.

## So why is this useful?

Three reasons:

1) including up numbers easily can be useful for estimation. Notice that the formula broadens to this:

Let’s say you desire to include the number from 1 come 1000: mean you acquire 1 extr visitor to your website each work – just how many complete visitors will certainly you have after 1000 days? since thousand squared = 1 million, we get million / 2 + 1000/2 = 500,500.

2) This ide of adding numbers 1 come N reflects up in various other places, prefer figuring the end the probability because that the birthday paradox. Having actually a firm understand of this formula will help your understanding in many areas.

3) most importantly, this instance shows over there are countless ways to understand a formula. Probably you like the pairing method, possibly you prefer the rectangle technique, or maybe there’s an additional explanation that functions for you. Don’t give up once you don’t recognize — try to find another explanation the works. Happy math.

By the way, there are an ext details around the history of this story and the method Gauss may have used.

## Variations

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

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

Sum native a to n = – <(a - 1) * a / 2>We want to get rid of every number from 1 up to a – 1.

See more: What Does Megan Mean In English, What Does Megan Mean

How around even numbers, prefer 2 + 4 + 6 + 8 + … + n?

Just twin the constant formula. To include evens native 2 come 50, uncover 1 + 2 + 3 + 4 … + 25 and double it:

Sum that 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 come 50 you’d perform 25 * (25 + 1) = 650

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

That’s the very same as the even formula, except each number is 1 much less than its counterpart (we have actually 1 rather of 2, 3 rather of 4, and so on). We obtain the next biggest also number (n + 1) and also 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, acquire 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 speak you desire the evens native 50 + 52 + 54 + 56 + … 100. Find all the evens

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

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

Phew! hope this helps.

Ruby nerds: friend can examine this using

(50..100).select x % 2 == 0 .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 are 51 number from 50-100, inclusive. Fencepost!