I am given two numbers $n,x$. I have to find the number of primes between them. Difference can be up to $10^6$; thus looping will take too much time. Is there any other way I can do it?
Asked
Active
Viewed 580 times
1
-
1There are various approaches to prime counting, which is what your Question amounts to. – hardmath Apr 11 '17 at 15:54
-
@hardmath my math knowledge can't understand those arduous formulas,could you simplify them for me and future nincompoops? – Murad Apr 11 '17 at 16:03
-
There is a simple approximation (Prime Number Theorem), but an exact counting formula is necessarily more complicated. The famous Riemann hypothesis is connected with adjustments to the approximation that make it into an exact count. If you actually want to identify all the primes in a consecutive range, a segmented Sieve of Eratothenes or variant would be attractive. Which of these would you like to learn about? – hardmath Apr 11 '17 at 17:22
-
@Murad see here this answer to a similar question: http://math.stackexchange.com/a/777047/189215 – iadvd Apr 12 '17 at 00:27