First, we look at your observation that
$$1+2+3+\cdots+n=\frac{n(n+1)}{2}.\tag{1}$$
If you are somewhat familiar with combinatorics, there is a nice way of seeing it via the binomial coefficient $\binom{n+1}{2}$, sometimes called $C(n+1,2)$ or $C_2^{n+1}$ (there are other names).
The right-hand side of (1) is the number of ways to choose $2$ numbers from the $n+1$ numbers $1$ to $n+1$. Let's count the number of ways to choose $2$ numbers in another way.
Maybe the second largest number chosen is $n$. There is then $1$ way of choosing the largest number.
Maybe the second largest number chosen is $n-1$. There are then $2$ ways to choose the largest number.
Maybe the second largest number chosen is $n-2$. There are then $3$ ways to choose the largest number.
Continue. Finally, if the second largest number chosen is $1$, there are $n$ ways to choose the largest number.
It follows that $\binom{n+1}{2}=1+2+3+\cdots +n$.
The nice thing about this viewpoint is that it generalizes. The same reasoning shows, for example, that
$$\binom{2}{2}+\binom{3}{2}+\binom{4}{2}+\cdots+\binom{n}{2} =\binom{n+2}{3}.\tag{2}$$
The binomial coefficient on the right of (2) is equal to $\frac{(n+2)(n+1)(n)}{3!}.$
The sum on the left of (2) is
$$\frac{(1)(2)}{2}+\frac{(2)(3)}{2}+\frac{(3)(4)}{2}+\cdots +\frac{n(n+1)}{2}.\tag{3}.$$
The sum (3) is a close relative of the sum of the first $n$ squares. For it is equal to
$$\frac{1}{2}\left(1^2+1+2^2+2+3^2+3+\cdots+n^2+n\right).$$
Since we already know the sum $1+2+3+\cdots +n$, we can now find a formula for the sum of the first $n$ squares. Putting things together, it is
$$2\frac{(n+2)(n+1)(n)}{3!} -\frac{n(n+1)}{2}.$$
Algebraic simplification (bring to common denominator $6$) then yields the hard to remember formula for the sum of the first $n$ squares.
It works pretty well for $p=2$.
– Taladris Jun 29 '13 at 05:09