Fractional part integral I have to calculate 
$$\int_0^1\text{frac}\left((nx)^2\right)\text dx$$
I know frac part has the period $1$ so shouldn't this be equal to $\dfrac{n^2}{3}$? In my book it says $\dfrac 13$, what am I calculating wrong?
 A: $\newcommand{\bbx}[1]{\,\bbox[15px,border:1px groove navy]{\displaystyle{#1}}\,}
 \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack}
 \newcommand{\dd}{\mathrm{d}}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,}
 \newcommand{\ic}{\mathrm{i}}
 \newcommand{\mc}[1]{\mathcal{#1}}
 \newcommand{\mrm}[1]{\mathrm{#1}}
 \newcommand{\pars}[1]{\left(\,{#1}\,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
 \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$

$\ds{\left.\int_{0}^{1}\braces{\pars{nx}^{2}}\dd x
\,\right\vert_{\ n\ =\ 0} = 0.\qquad
\left.\int_{0}^{1}\braces{\pars{nx}^{2}}\dd x
\,\right\vert_{\ n\ =\ 1} = {1 \over 3}}$.

\begin{align}
\left.\int_{0}^{1}\braces{\pars{nx}^{2}}\dd x\,\right\vert_{\ n\ \not=\ 0} & =
\int_{0}^{1}\pars{n^{2}x^{2} -\left\lfloor n^{2}x^{2}\right\rfloor}\dd x
\,\,\,\stackrel{\pars{nx}^{2}\ \mapsto\ x}{=}\,\,\,
{1 \over 3}\,n^{2} - \int_{0}^{n^{2}}\left\lfloor x\right\rfloor\,
{\dd x \over 2\verts{n}\root{x}}
\\[5mm] &=
{1 \over 3}\,n^{2} - {1 \over 2\verts{n}}
\int_{0}^{\left\lfloor n^{2}\right\rfloor}
{\left\lfloor x\right\rfloor \over \root{x}}\dd x -
{1 \over 2\verts{n}}\int_{\left\lfloor n^{2}\right\rfloor}^{n^{2}}
{\left\lfloor x\right\rfloor \over \root{x}}\dd x
\\[1cm] & =
{1 \over 3}\,n^{2} -
{1 \over 2\verts{n}}\sum_{k = 1}^{\left\lfloor n^{2}\right\rfloor - 1}
\int_{k}^{k + 1}{k \over \root{x}}\,\dd x
\\[2mm] & -
{1 \over 2\verts{n}}\,\left\lfloor n^{2}\right\rfloor
\pars{2\root{n^{2}} - 2\root{\left\lfloor n^{2}\right\rfloor}}
\\[1cm] & =
{1 \over 3}\,n^{2} -
{1 \over 2\verts{n}}\sum_{k = 1}^{\left\lfloor n^{2}\right\rfloor - 1}
k\pars{2\root{k + 1} - 2\root{k}} - \left\lfloor n^{2}\right\rfloor +
{\left\lfloor n^{2}\right\rfloor^{3/2} \over \verts{n}} 
\\[5mm] & =
\bbx{{1 \over 3}\,n^{2} - \left\lfloor n^{2}\right\rfloor +
{\phantom{^{3/2}}\left\lfloor n^{2}\right\rfloor^{3/2} \over \verts{n}} -
{1 \over \verts{n}}
\sum_{k = 1}^{\left\lfloor n^{2}\right\rfloor - 1}
{k \over \root{k + 1} + \root{k}}\,,\quad n \not= 0}
\end{align}

If $\ds{n \in \mathbb{Z}}$:

$$
\int_{0}^{1}\braces{\pars{nx}^{2}}\dd x =
\left\{\begin{array}{lcl}
\ds{{1 \over 3}\,n^{2} -
{1 \over \verts{n}}\sum_{k = 1}^{n^{2} - 1}{k \over \root{k + 1} + \root{k}}}
& \mbox{if} & \ds{n \not= 0}
\\
\ds{0} & \mbox{if} & \ds{n = 0}
\end{array}\right.
$$
A: Split the integral into $n$ equal width integrals
\begin{eqnarray*}
I=\int_0^{1} (\operatorname{frac}(nx))^2 dx = \sum_{i=0}^{n-1} \int_{\frac{i}{n}}^{\frac{i+1}{n}}  (\operatorname{frac}(nx))^2 dx.
\end{eqnarray*}
Within each interval $\frac{i}{n} \leq x \leq \frac{i+1}{n}$ so $0 \leq \operatorname{frac}(nx) \leq 1$ and $\operatorname{frac}(nx)$ will rise linearly from $0$ to $1$ within each interval. Substitute $t=nx$ so $\frac{dt}{n}= dx$
\begin{eqnarray*}
I= \sum_{i=0}^{n-1} \int_{\frac{i}{n}}^{\frac{i+1}{n}}  t^2 \frac{dt}{n} = \color{red}{\frac{1}{3}}.
\end{eqnarray*}
