Why does this sum converge: $\sum_{k=2}^{n-1} \frac{1}{k} \frac{n \mod k}{n}$

150 Views Asked by At

I was playing around with numbers and wanted to create a function that somehow indicates if a number could be a prime. So I came up with this, with the intention that it should make small jumps if $x$ is a prime number:

$$f(n) = \sum_{k=2}^{n-1}\frac{1}{k}\frac{n\mod k}{n}$$

It inneed does small jumps at small primes, but in general the term seems to converge to something close around $0.422780$.

Why is this? I would expect this sum to grow without bounds, as for a large number $N$, there should be a lot of numbers which do not divide $N$ without remainder.

f(n) in the range 0 to 1000

2

There are 2 best solutions below

1
On BEST ANSWER

We have $n\pmod{k}= k\{n/k\}$ where $\{x\}$ is the fractional part of $x$.
Hence we are interested in the behaviour of the sort-of-average-value $$ f(n)=\frac{1}{n}\sum_{k=2}^{n-1}\{n/k\} $$ which as $n\to \infty$, by Riemann sums, converges to $$ I = \int_{0}^{1}\left\{\frac{1}{x}\right\}\,dx \stackrel{x\mapsto 1/x}{=} \int_{1}^{+\infty}\frac{\{x\}}{x^2}\,dx = \sum_{m\geq 1}\int_{0}^{1}\frac{x}{(x+m)^2}\,dx $$ which equals $$\begin{eqnarray*} &&\sum_{m\geq 1}\left(\log(m+1)-\log(m)-\frac{1}{m+1}\right)\\ &=& \underbrace{\sum_{m\geq 1}\left(\frac{1}{m}-\frac{1}{m+1}\right)}_{1}-\underbrace{\sum_{m\geq 1}\left(\frac{1}{m}-\log\left(1+\frac{1}{m}\right)\right)}_{\gamma}\end{eqnarray*}$$ i.e. $\color{red}{1-\gamma}\approx 0.422784335$ as claimed by Daniel Fischer.

3
On

For a random number $n$ : $\mathbb{E}(n \mod k) = \frac{k}{2}$, so $\frac{1}{k} \cdot n \mod k = \frac{1}{2}$.

So, summing $(n-2)$ $\frac{1}{2}$'s and averaging I would expect to get to around $\frac{1}{2}$.