TITLE: Need help evaluating $\lim\limits_{n \to \infty} \frac{1}{n} \int_1^n \Vert\frac{n}{x}\Vert dx$
QUESTION [5 upvotes]: $$
\mbox{Evaluate}\quad
\lim_{n \to \infty}{1 \over n}\int_{1}^{n}\left\Vert\,n \over x\,\right\Vert
\,{\rm d}x
$$
Where $\left\vert\left\vert\, x\,\right\vert\right\vert : \mathbb{R} \to \mathbb{R}$ denotes the [distance to the] closest integer to $x$. As an explicit example,
$\left\Vert\, 4.7\,\right\Vert = 0.3 = \left\Vert\, 5.3\,\right\Vert$
I'm taking an advanced integration course at a mathematics academy and this is a problem in the problem set. I'd like to say that I've made some progress but I haven't. I'm not really sure what I could do to get started on the right track.

REPLY [2 votes]: We can split this integral into a sum of its parts in order to evaluate it more easily.
$$\frac{1}{n}\int_{1}^{n}\left\Vert\,n \over x\,\right\Vert
\,{\rm d}x = \frac{1}{n}\sum_{k=1}^{n-1}\int_{n/(k+1)}^{n/k}\left\Vert\,n \over x\,\right\Vert
\,{\rm d}x$$
Now to evaluate each integrand, we can split it up further
$$\int_{n/(k+1)}^{n/(k+1/2)} \left((k+1)-\frac{n}{x}\right)dx + \int_{n/(k+1/2)}^{n/k} \left(\frac{n}{x}-k \right)dx$$
$$=n\left(\frac{k+1}{k+\frac{1}{2}}-1\right)+n\ln\left(\frac{k+\frac{1}{2}}{k+1}\right)+n\ln \left(\frac{k+\frac{1}{2}}{k}\right)-n\left(1-\frac{k}{k+\frac{1}{2}}\right)$$
Now lots of stuff cancels out and we get the summation
$$\sum_{k=1}^{n-1}\ln\left(\frac{(k+\frac{1}{2})^2}{k(k+1)}\right)$$
This partial sum can be rewritten using the Gamma Function, which you probably studied in your advanced integration course, as
$$\ln\left(\frac{4}{\pi}\cdot \frac{\Gamma\left(n+\frac{1}{2}\right)^2}{\Gamma(n)\Gamma(n+1)}\right)$$
The $4/\pi$ term comes from the the fact that $\Gamma(3/2)=\sqrt{\pi}/2$. Taking the limit to infinity, the Gammas functions go to $1$ since
$$\lim_{n \to \infty}\frac{\Gamma(n+a)\Gamma(n+b)}{\Gamma(n)\Gamma(n+a+b)}=1$$
Thus we have 
$$\lim_{n \to \infty} \frac{1}{n}\int_{1}^{n}\left\Vert\,n \over x\,\right\Vert
\,{\rm d}x = \ln\left(\frac{4}{\pi}\right) \approx 0.24$$