TITLE: Limit of $\frac{1}{n}\sum_{r=1}^n\frac{n\ (\mathrm{mod}\ r)}{r}$
QUESTION [12 upvotes]: By accident I came across the following,
$$\lim_{n\to\infty}\frac{1}{n}\sum_{r=1}^n\frac{n\ (\mathrm{mod}\ r)}{r}=0.4227\ldots\approx 1-\gamma,$$
where the numerator is the remainder of $n$ divided by $r$. Is it known whether we have equality in the above expression or is it just a numerical coincidence? Has this been studied?
Edit: I'm sorry for all the (important) typos, everything should be fixed now.

REPLY [19 votes]: This follows by elementary computation: we have
\begin{align}
\sum_{r=1}^n\frac{n\bmod r}r&=\sum_{r\le n}\frac nr-\sum_{r\le n}\left\lfloor\frac nr\right\rfloor\\\\
&=nH_n-|\{(r,s)\in\mathbb N^2:1\le rs\le n\}|\\\\
&=nH_n-2\sum_{r\le\sqrt n}\left\lfloor\frac nr\right\rfloor+\lfloor\sqrt n\rfloor^2\\\\
&=nH_n-2nH_{\lfloor\sqrt n\rfloor}+n+O(\sqrt n),
\end{align}
hence
\begin{align}
\frac1n\sum_{r=1}^n\frac{n\bmod r}r&=H_n-2H_{\lfloor\sqrt n\rfloor}+1+O(n^{-1/2})\\
&=\log n+\gamma-2\log\lfloor\sqrt n\rfloor-2\gamma+1+O(n^{-1/2})\\\\
&=1-\gamma+O(n^{-1/2}).
\end{align}