Toolkit 2

Sum of squares

12+22++n2=n(n+1)(2n+1)61^2+2^2+\cdots+n^2=\frac{n(n+1)(2n+1)}{6}

Proof

Using the identity

(k+1)3k3=3k2+3k+1,(k+1)^3 - k^3 = 3k^2 + 3k + 1,

we have

2313=312+31+1,2^3 - 1^3 = 3\cdot 1^2 + 3\cdot 1 + 1,
3323=322+32+1,3^3 - 2^3 = 3\cdot 2^2 + 3\cdot 2 + 1,
\vdots
(n+1)3n3=3n2+3n+1.(n+1)^3 - n^3 = 3n^2 + 3n + 1.

Adding these identities, all intermediate terms on the left-hand side cancel, yielding

(n+1)31=3(12+22++n2)+3(1+2++n)+n.(n+1)^3 - 1 = 3(1^2 + 2^2 + \cdots + n^2) + 3(1 + 2 + \cdots + n) + n.

By Toolkit 1,

1+2++n=n(n+1)2.1 + 2 + \cdots + n = \frac{n(n+1)}{2}.

Hence,

3(12+22++n2)=(n+1)313n(n+1)2n=n(n+1)(2n+1)2.\begin{aligned} 3(1^2 + 2^2 + \cdots + n^2) &= (n+1)^3 - 1 - \frac{3n(n+1)}{2} - n \\ &= \frac{n(n+1)(2n+1)}{2}. \end{aligned}

Therefore,

12+22++n2=n(n+1)(2n+1)6.1^2 + 2^2 + \cdots + n^2 = \frac{n(n+1)(2n+1)}{6}. \quad\square