Odd Numbers Sum
Jane Street
Derive the formula for the sum of all odd numbers from 1 to n.
Answer
Let's assume you already know the sum of all numbers from 1 to n is $\frac{n\cdot (n+1)}{2}$. If you don't, remember it - it comes up often. How can we use this to get to our answer? Well notice that you can separate the sum of all numbers from 1 to n (call it $S_n$) into the sum of all even numbers ($E_n$) and all odd numbers ($O_n$). Namely: $$S_n=\frac{n\cdot (n+1)}{2}=E_n+ O_n$$But we don't want to be introducting a new variable $E_n$, so could there be a way to express $E_n$ in terms of $O_n$? Wheneve you're looking for a general pattern, evaluate a number of cases until the pattern shows up. So here are the first 8 even and odd sums: $$\begin{array}{|c|c|c|} \hline n & E_n & O_n \\ \hline 1 & 0 & 1 \\ 2 & 2 & 1 \\ 3 & 2 & 4 \\ 4 & 6 & 4 \\ 5 & 6 & 9 \\ 6 & 12 & 9 \\ 7 & 12 & 16 \\ 8 & 20 & 16 \\ \hline \end{array}$$Notice the pattern, when n is even, $E_n=O_n+\frac{n}{2}$; whereas when n is odd, $E_n=O_n-\frac{n+1}{2}$. Now we can separate these two cases and express $O_n$ in terms of $E_n$: $$\text{even n: }S_n=\frac{n\cdot (n+1)}{2}=O_n+O_n+\frac{n}{4}\Rightarrow O_n=\frac{n^2}{2}$$ $$\text{odd n: }S_n=\frac{n\cdot (n+1)}{2}=O_n+O_n-\frac{n+1}{2}\Rightarrow O_n=\frac{(n+1)^2}{4}$$And that's our answer: when n is even, $O_n=\frac{n^2}{4}$; when n is odd, $O_n=\frac{(n+1)^2}{4}$.