# For $n$ an even number and $p$ a prime, does $\lfloor {\frac {n}{4}} \rfloor= \frac{1}{\pi (n)-\pi (n/2)} \sum_{n/2<p<n} p-\frac {n}{2}$ hold?

I was playing around with prime numbers and I noticed that for $n$ an even number, the average of the distance between all primes between $n/2$ and $n$ and $n/2$ is equal to $\lfloor {\frac {n}{4}} \rfloor$, in an equation: $$\lfloor {\frac {n}{4}} \rfloor= \frac{1}{\pi (n)-\pi (n/2)} \sum_{n/2<p<n} p-\frac {n}{2}$$ I do not know any programming and so to check I must perform all operations by hand, still, I have been able to verify this for all numbers less than 100. I am, however, completely oblivious to the reason behind this or even if this pattern holds for all numbers beyond 100. I have tried to explain it through Bertrand's Postulate but so far I am stuck at square one.
My questions are: Does this pattern hold for all numbers? If it does, why?

• For $n=6$ the LHS is $1$ and the RHS is $2$. – Erick Wong Jul 13 '15 at 19:30
• @ErickWong hmmm, I must have made a mistake in the calculation. Are there any other counterexamples or is this a case of the "small numbers don't always work" phenomenon? – Guacho Perez Jul 13 '15 at 19:35
• @GuachoPerez Can you show some examples for bigger numbers? It looks like to me that RHS is not integer for many cases. – Abel Cheung Jul 13 '15 at 19:37
• 20: primes between 10 and 20 {11,13,17,19}, (11-10)+(13-10)+(17-10)+(19-10)=20, $20/4=5=\lfloor 20/4 \rfloor$ – Guacho Perez Jul 13 '15 at 19:57
• @GuachoPerez I suspect this is a case of the "only a handful of small numbers work" phenomenon. It's really difficult to believe there exists any exact non-trivial linear relation between $\pi(n)$ and the summatory function of primes. As Abel notes, why should the RHS even be an integer when $n$ is large? – Erick Wong Jul 13 '15 at 20:10

I think this is a compelling argument that nothing of the sort is true for most $n$: let $n$ be chosen such that neither $n+1$ nor $n/2+1$ is prime (by PNT, this holds for most $n$, and more explicitly one can take $n = 12k+2$).
Now consider going from $n \mapsto n+2$. The set of primes in the summation on the RHS does not change at all (since $(n+2)/2$ isn't prime, no primes are lost at the low end, and $n+1$ isn't prime so no primes are introduced at the high end). But the average value decreases by exactly $1$ (since $n/2$ increases). Furthermore, the LHS increases by either $0$ or $1$. So the equality cannot possibly hold for both $n$ and $n+2$.