My problem reduces to finding the number of primes between two given numbers.I could have a range as big as 1 to (1000)! and hence I am need of some mathematical optimizations.
Clearly the sieve method would be too slow in this case. Is there any mathematical optimization that can be applied – like for instance, taking a smaller subset of this large space and making inferences about the rest of the numbers.
P.S: It definitely looks like I might have reached a dead end – but all that I am looking for are some optimizations that could possibly help solve this. And also, I am only looking for a single-threaded approach.
EDIT: One approach I have been thinking and can solve a lot of large prime number related problems – is for someone to maintain a global table of primes and make it available for lookup. Folks at the PrimeGrid project can contribute usefully towards this.
Since you want to go as high as
1000!(factorial). You will not be able to get exact results with currently known methods on current technology.The Prime Counting Function has only been evaluated exactly for a handful of values up to
10^24. So no way you’ll be able to hit1000!.But since you mention than an approximation may be fine, you can use the Logarithmic Integral as an approximation to the Prime Counting Function.
This is based on the Prime Number Theorem which says that the Prime Counting Function is asymptotic to the Logarithmic Integral.