$A=1^2+2^2+3^2+4^2..+n^2=1+(1+1).2+(1+2).3+(1+3).4+...+(1+n-1).n$$=1+(2+1.2)+(3+2.3)+(4+3.4)...+n+(n-1)n$
$=(1+2+3+..+n)+[1.2+2.3+3.4+4.5+...(n-1)n]$
Ta có $1+2+3+...+n=\frac{(n+1).n}{2}$
$B=1.2+2.3+3.4+..+(n-1).n$
$\Rightarrow 3B=1.2.(3-0)+2.3(4-1)+3.4(5-2)+...+n.(n-1)[(n+1)-(n-2)]$
$3B=1.2.3+2.3.4-1.2.3+3.4.5-2.3.4+....+(n-1)n(n+1)-(n-2)(n-1)n$
$3B=(n-1)n(n+1)\Rightarrow B=\frac{(n-1)n(n+1)}{3}$
$\Rightarrow A=\frac{n(n+1)}{2}+\frac{(n-1)n(n+1)}{3}=\frac{3n(n+1)+2(n-1)n(n+1)}{6}=\frac{n(n+1)(2n+1)}{6}$