What is the complexity of finding the 1000th prime number problem?
I think it is P time.
I just write a function to test if a given number a prime number,then call it in a loop to accumulate it.
right
http://www.cse.iitk.ac.in/users/manindra/algebra/primality_v6.pdf This paper shows that the complexity is PTIME
so you check every prime number til the 1000th one, then accumulate it?
Actually, I write another two functions.,one is to find the prime number not bigger than 1000,the other one to find the 1000th prime number . check then count or append it to a list.
There's an efficient algorithm to find prime number not bigger than n: the sieve of eratosthenes (there are other sieves but the sieve of eratosthenes is probably the simplest one and still works very fast): http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
Here's a python implementation: http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Python
Try to get people to 'think' about the problem...not get the answer right out!!!
Join our real-time social learning platform and learn together with your friends!