How do I come up with a function to count a pyramid of apples? My algebra book has a quick practical example at the beginning of the chapter on polynomials and their functions. Unfortunately it just says "this is why polynomial functions are important" and moves on. I'd like to know how to come up with the function (the teacher considers this out of scope). Even suggesting google search terms to find out more information on this sort of thing would be helpful.
The example
Consider a stack of apples, in a pyramid shape. It starts with one apple at the top. The next layer is 2x2, then 3x3, and so on. How many apples are there, given x number of layers?
The polynomial function
$$f(x) = \frac{2x^3 + 3x^2 + x}{6}$$
What I do and don't understand
Thanks to @DJC, I now know this is a standard function to generate Square Pyramidal Numbers, which is part of Faulhaber's formula. Faulhaber's formula appears to be about quickly adding sequential coefficients which all have the same exponent. Very cool. But how does one get from:
$$\sum_{k=1}^{n} k^p$$
to the spiffy function above? If I'm sounding stupid, how do I make the question better?
Fwiw, I'm in intermediate algebra in the USA. The next course would be Trigonometry or Calculus. (to help people place my current knowledge level)

The first layer has $1^2$ elements; the second has $2^2$ elements; the next has $3^2$ elements, and so on. 
So this is a matter of finding the formula for
$$1^2 + 2^2 + 3^2 + \cdots + n^2$$
in terms of $n$. 
For squares, this is a well known formula: $1^2+2^2+\cdots +n^2 = \frac{n(n+1)(2n+1)}{6}$.
Note that 
$$\frac{n^3}{3} + \frac{n^2}{2} + \frac{n}{6}  = \frac{2n^3 + 3n^2 + n}{6} = \frac{n(2n^2+3n+1)}{6} = \frac{n(2n+1)(n+1)}{6}$$
same formula.
Of course, you might be more interested in how to figure out the formulas in the first place. How does one express $1^k + 2^k + 3^k + \cdots + n^k$?
This is known as Faulhaber's formula. For the general case,
$$1^p + 2^p + \cdots + n^p = \frac{1}{p+1}\sum_{j=0}^p(-1)^jB_j\binom{p+1}{j} n^{p+1-j}$$
where $B_m$ is the $m$th Bernoulli number.
For $p=2$, you get the spiffy formula with:
\begin{align*}
1^2+\cdots+n^2 &= \frac{1}{3}\left(\binom{3}{0}B_0n^3 - \binom{3}{1}B_1n^2 + \binom{3}{2}B_2n - \binom{3}{3}B_3\right)\\
&= \frac{1}{3}\left(B_0n^3 - 3B_1n^2 + 3B_2n - B_3\right)\\
&= \frac{1}{3}\left(n^3 - 3\left(-\frac{1}{2}\right)n^2 + 3\left(\frac{1}{6}\right)n - 0\right)\\
&= \frac{1}{3}n^3 +\frac{1}{2}n^2 + \frac{1}{6}n\\
&= \frac{n^3}{3} + \frac{n^2}{2} + \frac{n}{6},
\end{align*}
using the fact that $B_0 = 1$ $B_1 = -\frac{1}{2}$, $B_2 = \frac{1}{6}$, and $B_3=0$ (in fact, $B_n = 0$ for all odd $n\gt 1$). 
