A formular for finding how many prime numbers there are below a number

351 Views Asked by At

With $f(n)=8n+8(n-1)+8(n-2)+\cdots+(8\cdot1)+1$, it is possible to calculate how many primes there are below $f(n)$ using $P(n)=\frac{n(n+1)}{2}+3n$.

Example: When $n=3$, $f(3)=49$ and $P(3)=15$.

That means below 49 there are 15 primes.

It is also possible to know how many primes are between $f(x_1)$ and $f(x_0)$ using $p(x_1)-p(x_0)$

Is this a known formula? I tested this with a bunch of numbers I counted manually using Ulam Spiral. I would like to know whether my thinking is right.

How did I came to this conclusion:

I noticed that in Ulam Spiral every time the spiral goes around it contains exactly 8 more numbers than the last one and exactly one more prime number than the last round.

Example:

  • first round (2-9) has 8 numbers and 4 primes
  • second round (10-25) has 16 numbers and 5 primes
  • third round (26-49) has 24 numbers and 6 primes

and so on.

3

There are 3 best solutions below

0
On BEST ANSWER

This formula first fails at $n=7$, where it predicts $49$ primes below $225$ but in fact there are only $48$.

The error increases as $n$ increases, for example for $n=100$ the formula predicts $5350$ primes below $40401$ but there are actually only $4236$.

0
On

The formula is not correct. Your claim is that up to $(2n+1)^2$ there are $\frac 12n(n+7)=\frac 12n^2+\frac 72n$ primes. In fact for $n=8$ your formula predicts $60$ primes and there are $61$. It predicts that the density of primes approaches $\frac 18$, while we know it approaches $0$ about as $\frac 1{\log n}$

0
On

One can also show this fails by using $\pi(n)\sim\frac{x}{ln(x)}$, the Prime Number Theorem. With your $P(n)$, this limit fails at infinity.