TITLE: Is it true that if $n$ is even then $\sum_{k=1}^{n}(n \bmod k)<\frac{8}{45}n^2$?
QUESTION [5 upvotes]: Let $f(n,k)$ be the least non-negative integer such that $n\equiv f(n,k) \bmod k.$
$f(10,k)(k=1,2,\cdots,10)=0, 0, 1, 2, 0, 4, 3, 2, 1, 0.$ 
Hence $$\sum_{k=1}^{10}f(10,k)=1+2+4+3+2+1=13.$$

Question: Is it true that if $n$ is even then$$\sum_{k=1}^{n}f(n,k)<\frac{8}{45}n^2\tag?$$

This is true for $n<10^5,$ but not true for many odd integers, such as $11,23,29,35,47,53,59,\cdots$
Eidt: Does $$\lim_{n\to \infty}\frac{1}{n^2}\sum_{k=1}^{n}f(n,k)$$ exist?

REPLY [6 votes]: Apply $n\bmod k = n - k \big\lfloor \frac{n}{k} \big\rfloor$ to $$g(n) = \sum_{k=1}^n (n\bmod k)$$
to get $$g(n) = n^2 - \sum_{k=1}^n k \bigg\lfloor \frac{n}{k} \bigg\rfloor.$$
Introduce $$q(n) = \sum_{k=1}^n k \bigg\lfloor \frac{n}{k} \bigg\rfloor$$
and observe that $$q(n+1)-q(n) = (n+1) \bigg\lfloor \frac{n+1}{n+1} \bigg\rfloor
+ \sum_{k=1}^n k 
\left(\bigg\lfloor \frac{n+1}{k} \bigg\rfloor 
- \bigg\lfloor \frac{n}{k} \bigg\rfloor\right)
\\= n+1 + \sum_{d|n+1\atop d <n+1} d = \sigma(n+1).$$
Therefore $$q(n) = \sum_{k=1}^n \sigma(n).$$
Now recall that
$$\sum_{n\ge 1}\frac{\sigma(n)}{n^s} = \zeta(s)\zeta(s-1)
\quad\text{and}\quad 
\mathrm{Res}\left(\zeta(s)\zeta(s-1); s=2\right) = \frac{\pi^2}{6}.$$
Hence by the Wiener-Ikehara theorem
$$ \sum_{k=1}^n \sigma(n) \sim \frac{\pi^2}{6} \frac{n^2}{2} = \frac{\pi^2}{12} n^2.$$
It follows that
$$ g(n) \sim \left(1-\frac{\pi^2}{12} \right) n^2$$
and the conjectured limit exists.
This approximation is quite good, e.g. we have $g(2000) = 708989$ and the approximation gives $710132.$
Even better we may use Mellin-Perron summation and include the pole at one which has residue $-1/2$, 
$$\mathrm{Res}\left(\zeta(s)\zeta(s-1); s=1\right) = -\frac{1}{2}$$
plus a correction term to get
$$g(n) \sim \left(1-\frac{\pi^2}{12} \right) n^2 + \frac{1}{2} n - \frac{1}{2}\sigma(n).$$
This last approximation is excellent, it gives $708714$ for $n=2000$ and for $n=8000$ with exact value $g(8000)=11356914$ it gives $11356203.$ For $n=16000$, we have $g(16000) = 45437799$ and the approximation gives $45436549.$
Observe that
$$\frac{8}{45} \approx 0.1777777778
\quad\text{and}\quad 1-\frac{\pi^2}{12} \approx 0.1775329664$$
so the conjectured coefficient was very close to the asymptotic one.