First n Integers Sum
Jane Street
Derive the formula for the sum of the first n integers.
Answer
When you want to derive a pattern like this, evaluate a number of cases and see if you can notice a rule that repeats.The sum of first n numbers is as follows for the first 8 integers: $$n=1:\,S_1=1$$ $$n=2:\,S_2=1+2=3$$ $$n=3:\,S_3=1+2+3=6$$ $$n=4:\,S_4=1+2+3+4=10$$ $$n=5:\,S_5=1+2+3+4+5=15$$ $$n=6:\,S_6=1+2+3+4+5+6=21$$ $$n=7:\,S_7=1+2+3+4+5+6+7=28$$ $$n=8:\,S_8=1+2+3+4+5+6+7+8=36$$Now what can we notice? Firstly, given the previous sum $S_{n-1}$, we can obtain the next one by adding n, i.e. $S_n=S_{n-1}+n$. Now if we can find another equation relating $S_n$ and $S_{n-1}$, we'll have two equations with two unknowns, which we can solve.
Notice now that we can write $S_n$ as: $$S_n=n + (n-1)+(n-2)+..+(n-(n-1))$$ Now we have n terms alltogether, so we can group the ns and what we substract from them to get: $$S_n=n\cdot n - (1+2+...+(n-1))$$Notice the sum of all the terms we are substracting is simply $S_{n-1}$! Therefore we have $$S_n=n^2-S_{n-1}$$Now we have a system of two equations and two unknowns, so we can combine them to get: $$n^2-S_{n-1}=S_{n-1}+n\Rightarrow S_{n-1}=\frac{n\cdot (n-1)}{2}$$And therefore $S_n=\frac{n\cdot(n+1)}{2}$ which is the well-known expression we were after.