General formula for a sum of quadratic sequence

$$\begin{align*}\sum_{i=1}^3(2+i)^2 &= \sum_{j=3}^5 j^2&&(j=2+i)\\ &= \sum_{j=1}^5 j^2 - \sum_{j=1}^2 j^2\\ &= \sum_{j=1}^5 j^2 - 5 \end{align*}$$


You cannot use the formula with $2+n$, because that means you are calculating $\sum_{j=1}^{2+n} j^2$. What you want to do is $$ \sum_{j=1}^m(2+j)^2=\sum_{j=3}^{m+2} j^2=\frac{(m+2)(m+3)(2(m+2)+1)}{6}-1^2-2^2. $$ More generally, \begin{align} \sum_{j=n}^m(k+j)^2&=\sum_{j=k+n}^{k+m}j^2=\sum_{j=1}^{k+m}j^2-\sum_{j=1}^{k+n-1}j^2 \\ \ \\ &=\frac{(k+m)(k+m+1)(2k+2m+1)}{6}-\frac{(k+n-1)(k+n)(2(k+n-1)+1)}{6} \end{align}


Here are two approaches

  • reindexing: $$\sum_{i=1}^n (k+i)^2 = \sum_{j=k+1}^{n+k} j^2 = \sum_{j=1}^{n+k}j^2 - \sum_{j=1}^k j^2 = \frac{(n+k)(n+k+1)(2n+2k+1) - k(k+1)(2k+1)}{6}$$
  • expanding: $$\sum_{i=1}^n (k+i)^2 = \sum_{i=1}^n(k^2+2ki+ i^2) = nk^2 + 2k\sum_{i=1}^n i + \sum_{i=1}^n i^2 = nk^2 + kn(n+1) + \frac{n(n+1)(2n+1)}{6}$$

If you plug in $k=2$ and $n=3$ you get $50$ in both cases. In general the two expressions are equal.