Question
I want to print the first 10000 prime numbers. Can anyone give me the most efficient code for this? Clarifications:
- It does not matter if your code is inefficient for n >10000.
- The size of the code does not matter.
- You cannot just hard code the values in any manner.
Answer
The Sieve of Atkin is probably what you're looking for, its upper bound running time is O(N/log log N).
If you only run the numbers 1 more and 1 less than the multiples of 6, it could be even faster, as all prime numbers above 3 are 1 away from some multiple of six. Resource for my statement
< br > via < a class="StackLink" href=" http://stackoverflow.com/questions/622/" >Most efficient code for the first 10000 prime numbers?< /a>
0 comments:
Post a Comment