Error in proving of the formula the sum of squares Given formula
$$
\sum_{k=1}^n k^2 = \frac{n(n+1)(2n+1)}{6}
$$
And I tried to prove it in that way:
$$
\sum_{k=1}^n (k^2)'=2\sum_{k=1}^n k=2(\frac{n(n+1)}{2})=n^2+n
$$
$$
\int (n^2+n)\ \text d n=\frac{n^3}{3}+\frac{n^2}{2}+C
$$
But 
$$
\frac{n^3}{3}+\frac{n^2}{2}+C $$ is not equal to 
$$\frac{n(n+1)(2n+1)}{6}=\frac{n^3}{3}+\frac{n^2}{2}+\frac{n}{6}$$
Where I made a mistake?

We must take (anti)derivatives in terms of specific variables. The sum $$\sum_{k=1}^n k^2$$ is not a function of $k,$ but rather a function of $n,$ for which you're trying to find a formula. Consequently, $(k^2)'$ makes no sense, as every instance of $k$ is a fixed constant, not an undetermined variable.
