Integer Sum Formula (Gauss Sum)
How do we find the sum of the numbers 1 through 100?
Summary
How do we find the sum of the numbers 1 through 100?
For example,
In code this would look like
let sum = 0;
for (let i = 1; i <= 100; i++){
sum += i;
}
If you sum up these numbers, the result will be
Sum of n Integers Equation
Instead of adding up the numbers 1 through by hand or in a loop, we can use an equation to find the answer instantly.
This is the equation for the sum of integers 1 through
We can use this equation to find the sum of numbers 1 through 100
We do the calculations to find our answer
Proof
Visual Proof
One way of looking at the problem is to imagine stacking boxes like a set of stairs
You have one box, two boxes, three boxes stacked, etc
The bottom and side are both length n. We need to find the “area” to find the total sum
We can create a square by duplicating this stack and flipping it upside down
![](/_astro/image_1665465573710_0.CVMxB6Iu_ZBCWEy.webp)
Notice by flipping it, one side is n and the other is n +1
The area of a square is length time width, which is in this square
We need to divide this by two, because we only want the blue staircase part
This gives us the final equation
Proof by Induction
Base Case
The base case is just the sum of the first number, , so let
Inductive Step
Now lets find the next sum, in terms of
To find the next sum, we take the sum so far, and add the next number to it.
We replace the summation part with the original equation and simplify
We get a common denominator, so we can add the two terms. We replace (n+1) with the equivalent 2(n+1)/2
Factor out the common in both terms
We can modify it to look like the original equation
This is really similar to the original equation, but with in place of
vs
This shows how you can validate the equation is correct using induction. We start with the known base case, then show that given n, we can find any n+1