## Limit of $\frac{1}{n}\sum_{r=1}^n\frac{n\ (\mathrm{mod}\ r)}{r}$

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.

-
 Without conditions on n, I have a hard time believing that lim inf of the sum is as large as you claim. I do not think the limit exists. Gerhard "Ask Me About System Design" Paseman, 2012.04.17 – Gerhard Paseman Apr 17 2012 at 14:48 The text is incorrect (should be the remainder of $n$ divided by $r$) – Igor Rivin Apr 17 2012 at 14:56 Can the OP prove this, or is this an experimental fact? – Igor Rivin Apr 17 2012 at 14:56 Further, I see no way of rescuing the problem without making the denominator substantially bigger, as in r^2 or n^2, or making the numerator correspondingly smaller. Gerhard "Ask Me About System Design" Paseman, 2012.04.17 – Gerhard Paseman Apr 17 2012 at 14:57 @Igor: thanks for spotting the typo. And no, I cannot prove this, this is purely experimental. – unknown Apr 17 2012 at 14:59

To add to Emil's nice answer: The determination of the OP's limit is implicit in Dirichlet's estimate for the average order of the divisor function, namely $\sum_{k=1}^{n} d(k) = n \log{n} + (2\gamma-1)n + O(\sqrt{n})$. (See section 18.2 in Hardy and Wright, for example.) To see the connection, notice that the sum in question is exactly the number of ordered pairs of natural numbers $(r,s)$ with $rs \leq n$ (and now compare with Emil's answer above). – Anonymous Apr 17 2012 at 16:32
@Anonymous: Yes, I guess I should have mentioned in the answer that this estimate of $\sum_{r\le n}\lfloor n/r\rfloor$ is a classical fact. – Emil Jeřábek Apr 18 2012 at 16:11