# Integral of a Piece-wise Function

### Source

Dorin Marghidanu has kindly posted at the CutTheKnotMath facebook page the following problem:

### Solution 1

We have, $x\cdot [x]\cdot \{x\}=x\cdot [x]\cdot (x-[x])=[x]\cdot x^2-[x]^2\cdot x.\qquad$ Hence,

\displaystyle\begin{align} I_n &= \int_{1}^{n}x\cdot [x]\cdot \{x\}dx\\ &=\int_{1}^{n}([x]\cdot x^2-[x]^2\cdot x)dx\\ &=\sum_{k=1}^{n-1}\int_{k}^{k+1}([x]\cdot x^2-[x]^2\cdot x)dx\\ &=\sum_{k=1}^{n-1}\int_{k}^{k+1}(k\cdot x^2-k^2\cdot x)dx\\ &=\sum_{k=1}^{n-1}\left[k\cdot\frac{x^3}{3}-k^2\cdot\frac{x^2}{2}\right]\\ &=\sum_{k=1}^{n-1}\left[k\cdot\frac{(k+1)^3}{3}-k^2\cdot \frac{(k+1)^2}{2}-k\cdot\frac{k^3}{3}+k^2\cdot\frac{k^2}{2}\right]\\ &=\frac{1}{6}\sum_{k=1}^{n-1}k\cdot (3k+2)\\ &=\frac{1}{6}\cdot\left[3\cdot\frac{(n-1)\cdot n\cdot (2n-1)}{6}+2\cdot\frac{(n-1)\cdot n}{2}\right]\\ &=\frac{(n-1)\cdot n\cdot (2n+1)}{12}. \end{align}

### Solution 2

\displaystyle\begin{align} \int_1^n x\cdot [x]\cdot \{x\}dx &= \sum_{r=1}^{n-1}\int_{r}^{r+1}x\cdot r\cdot (x-r)dx\\ &=\sum_{r=1}^{n-1}\int_{0}^{1}rx(x+r)dx\\ &=\int_{0}^{1}\left\{\sum_{r=1}^{n-1}(x^2r+xr^2\right\}dx\\ &=\frac{1}{3}\frac{n(n-1)}{2}+\frac{1}{2}\frac{n(n-1)(2n-1)}{6}\\ &=\frac{n(n-1)(2n+1)}{12}. \end{align}

### Acknowledgment

Solution 1 is by Dorin Marghidanu; Solution 2 is by Shafiqur Rahman.