What would be the closed form of $n\cdot n + (n-2)\cdot(n-2) + (n-4)\cdot(n-4) + \dots$?

138 Views Asked by At

As part of solving this problem , I came up with the following expression:

$$\text{ans} = n\cdot n + (n-2)\cdot (n-2) + (n-4)\cdot (n-4) + \dots$$

So I am just running a loop to calculate the ans. However, since there is a pattern in the form of a series, I am wondering if a closed form exists for it? Please also show the steps to obtain so that I can learn, in general, how to approach such problems for finding closed forms.

EDIT: series goes till 2 if n is even, and till 1 if n is odd.

5

There are 5 best solutions below

0
On BEST ANSWER

It is well known that the sum of terms that are a polynomial expression of degree $d$, evaluated at the integers, is a polynomial expression of degree $d+1$.

So if you consider four values of the sum, you can obtain the requested expression as the Lagrangian interpolation polynomial on these four points.

For even $n$,

$$(0,0),(2,4),(4,20),(6,56)\to\frac{n^3+3n^2+2n}6.$$

For odd $n$,

$$(1,1),(3,10),(5,35),(7,84)\to\frac{n^3+3n^2+2n}6.$$

1
On

Use the classic formula for the sum of increasing squares and some manipulation to find:

$$\frac{1}{3} \left(\left\lfloor \frac{n-1}{2}\right\rfloor +1\right) \left(2 \left\lfloor \frac{n-1}{2}\right\rfloor +1\right) \left(2 \left\lfloor \frac{n-1}{2}\right\rfloor +3\right)$$

0
On

An alternative method:

Let's call the sum of alternate squares up to $n$ by $s(n)$.iafor $n=0,1,2,3,4,5,6$ is

$0,1,4,10,20,35, 56$

The differences between these terms are:

$1,3,6,10,15,21$

which are the triangular numbers $\frac{n(n+1)}{2}$. So this suggests that

$s(n) = \sum_{m=0}^{n} \frac{m(m+1)}{2}$

$= \sum_{m=0}^{n} (\frac{m^2}{2} + \frac{m}{2})$

$=\frac{n(n+1)(2n+1)}{12} + \frac{n(n+1)}{4}$

$=\frac{n(n+1)(2n+1) + 3n(n+1)}{12}$

$ = \frac{n(n+1)(n+2)}{6}$

This is not a formal proof, but it does suggest a formula which can form the starting point of a proof by induction

0
On

If $n$ is even, you have

$ \begin{align} \sum_{k=1}^{\frac{n}2}(2k)^2&=4\sum_{k=1}^{\frac{n}2}k^2\\ &=4\cdot\frac{\frac{n}2(\frac{n}2+1)(2\cdot\frac{n}2+1)}6\\ &=\frac{n(n+1)(n+2)}6 \\ \text{If $n$ is odd, you have} \\ \\ \sum_{k=1}^{\frac{n+1}2}(2k-1)^2&=4\sum_{k=1}^{\frac{n+1}2}k^2-4\sum_{k=1}^{\frac{n+1}2}k+\sum_{k=1}^{\frac{n+1}2}1 \\ &=4\cdot\frac{\frac{n+1}2(\frac{n+1}2+1)(2\cdot\frac{n+1}2+1)}6-4\cdot\frac{\frac{n+1}2(\frac{n+1}2+1)}2+\frac{n+1}2 \\ &=\frac{n(n+1)(n+2)}6 \end{align}$

0
On

Since $x^2=\frac{x(x+1)}2+\frac{(x-1)x}2$, your sum becomes $$\sum_{k=1}^n\frac{k(k+1)}2=\frac{n(n+1)(n+2)}6$$