Formula for the sum of $\ n\cdot 1 + (n-1)\cdot 2 + … + 2 \cdot (n-1) + 1\cdot n$ [duplicate]

I'm looking for a simpler formula to calculate this sum:

$$n\cdot 1 + (n-1)\cdot 2 + ... + 2 \cdot (n-1) + 1\cdot n$$ Alternate representation (but should be equal to the above): $$\sum \limits_{k=1}^{n}(n+1-k)\cdot k$$

Rationale behind requested formula

When reviewing code implementing a minion game, the problem of how many substrings exists within a long text, and how many characters will the sum of all these substrings be came up. I found that the number of substrings is:

$$n + n-1 + n-2 + ... + 2 + 1 = \frac{(n+1)\cdot n}{2}$$

Reasoning for finding number of substrings is that you have $n$ substrings of length $1$, $n-1$ of length $2$, and so on until the end where you only have $1$ substring of length $n$.

Using the same logic, to sum up the length of all these substrings, we arrive at the formula at the top, which I would like to have simplified. That is, multiply the count of substrings with the length of the substring, and sum all these.

I have found the article "The Kth Sum of N Numbers", which seems to produce the number I want in the column for c3, with the $n$ enumerated as $rN$. But I can't read out of this article how the column is calculated, and what formula to use.

\begin{align} \sum_{k=1}^{n}(n+1-k)\cdot k&=\sum_{k=1}^{n}(n+1)k-\sum_{k=1}^n k^2\\ &=(n+1)\sum_{k=1}^n k-\sum_{k=1}^n k^2\\ &=\frac{n(n+1)^2}{2}-\frac{n(n+1)(2n+1)}{6}\\ &=\frac{n(n+1)(3n+3-2n-1)}{6}\\ &=\frac{n(n+1)(n+2)}{6} \end{align}

• For me, not too proficient in maths, this is by far the easiest to follow from start through end. – holroy Oct 1 '15 at 17:22
• @holroy: Thanks. – Ángel Mario Gallegos Oct 1 '15 at 17:23

Imagine that you’re to choose $3$ numbers from the set $A=\{0,\ldots,n+1\}$. If the middle number of your three is $k$, there are $k$ choices for the smallest number and $n+1-k$ choices for the largest number, so there are altogether $k(n+1-k)$ sets of $3$ having $k$ as the middle number. Clearly $k$ must range from $1$ through $n$, so there are altogether

$$\sum_{k=1}^nk(n+1-k)$$

ways to choose $3$ members of the set $A$. On the other hand, $A$ has $n+2$ members, so it has $\binom{n+2}3$ three-element subsets. Thus,

$$\sum_{k=1}^nk(n+1-k)=\binom{n+2}3=\frac{n(n+1)(n+2)}6\;.$$

• Even though I'm a master of Computer Science, it's been too long since I've studied math to easily follow your logic. But with a bit of thinking it does make sense, with exception of the last transformation (which I surely could look up somewhere). But I, by myself, would never have thought about this problem this way... – holroy Oct 1 '15 at 17:33
• @holroy: You can get it from the Wikipedia article on binomial coefficients, in particular this section. – Brian M. Scott Oct 1 '15 at 17:43

Hint: the sum is equal to $$(n+1)\sum^n_{k=1}k-\sum^n_{k=1}k^2.$$

Your sum is just the coefficient of $x^{n+1}$ in the product between $x+2x^2+3x^3+\ldots+n\,x^n$ and itself. It follows that:

\begin{align*} \sum_{j=1}^{n} j(n+1-j) &= [x^{n+1}]\left(\frac{x}{(1-x)^2}\right)^2 \\&= [x^{n-1}]\frac{1}{(1-x)^4}=\binom{n+2}{3}=\color{red}{\frac{(n+2)(n+1)n}{6}}.\end{align*}

• How do you see that? Is it just common knowledge that it is this coefficient? – holroy Oct 1 '15 at 17:29
• @holroy: multiply by hand $x+2x^2+\ldots+nx^n$ and $x+2x^2+\ldots+nx^n$, then check what is the coefficient of $x^{n+1}$. It is clearly the coefficient of $x$ times the coefficient of $x^n$, plus the coefficient of $x^2$ times the coefficient of $x^{n-1}$ and so on. You just made you first step in analytic combinatorics ;) – Jack D'Aurizio Oct 1 '15 at 17:34

\begin{align} \sum_{k=1}^n(n+1-k)k&=\sum_{k=1}^n\sum_{j=k}^nk=\sum_{1\le k\le j\le n}k =\sum_{j=1}^n\sum_{k=1}^jk\\ &=\sum_{j=1}^n \binom {j+1}2=\binom {n+2}3\color{lightgrey}{=\frac{(n+2)(n+1)n}6}\qquad\blacksquare \end{align}