6

Is there any algorithm or a technique to calculate how many prime numbers lie in a given closed interval [a1, an], knowing the values of a1 and an, with a1,an ∈ ℕ?

Example:

[2, 10] --> 4 prime numbers {2, 3, 5, 7}

[4, 12] --> 3 prime numbers {5, 7, 11}

alienflow
  • 349

2 Answers2

2

Use the prime-counting function and get $\pi(a_n)-\pi(a_1-1)$

gammatester
  • 19,147
2

The prime number theorem gives an approximation to $\pi(n),$ the number of primes less than $n$. You can subtract the values at the start and end of an interval. Mathematica and other software can compute exact values for small values of $n$ and approximate values for larger values of $n$. The first approximation is $\pi(n) \sim \frac n{\log n}$ but a much better one is $$\pi(n)\sim \int_2^n \frac {dt}{\log t}$$

Ross Millikan
  • 383,099