AlphaNumeric
23rd June 2009 - 10:59 AM
You are still doing more work than required. Suppose I give you the range 1,000,000 to 1,000,1000. How would you find the primes in that?
Your method seems to be "Why waste time seeing if p is prime when you could just check the numbers p-10, p-9, ...., p+9, p+10 and if they are all non-prime then p is prime". Am I wrong in that assessment? Because that method requires you to check if 20 numbers are prime to see if p is prime. Further more, the distribution of the primes is currently only understood statistically, you can't say "Well when p is about 1000 there's only 1 prime in 20, so there's definitely a prime between p-10 and p+10". For instance, between 20 and 30 there's 2 primes, 23 and 29. Between 40 and 50 there's 3, 41, 43 and 47. Your logic would fail because if you found 41 and 43 you'd say "There can't be more than 2 in 10 so move onto numbers larger than 50".
The
pi function can give us an idea of roughly how many primes are in a given interval, but it is not exact.
If I give you 582850385283, how would you check if it's prime? Your method seems to be to consider 580000000000 through to 590000000000, sampling some of them and saying something like "I've checked 1% of the possible values and found 1 in 1000 are prime, so it's unlikely your number of prime". Rather than factorising the number I give you your method factorises (or tries to)other numbers then guesses (using the pi function asymptotic expression someone else has provided you) as to the likelihood the given number is prime. Why not just check the number itself?
Yes, in an ideal world you'd just set a computer running the number sieve so you end up with a list of numbers which aren't prime and thus can see if a given number is on the list but it's very slow and VERY memory intensive. The size of the largest prime is into the
millions of digits. To construct a FULL list of all primes smaller than it would be too slow. Which is quicker, factorise p of order 1,000,000,000,000 or work out all primes (or non-primes) less than 1,000,000,000,000?