I was curious about prime numbers and would like to know the most efficient way to find relatively small prime numbers for a range up to say, 10 million. I read that the sieve of erastosthenes (SOE) is the most efficient way to find smaller prime numbers. I implemented SOE using python but had a few questions:
The worst case running time of my algorithm seems to be O(n^2). I'm still learning, so I know this algorithm can be made more efficient.
Is there a difference in the most efficient mathematical way and most efficient programming way to find prime numbers? Mathematically, SOE is one of the fastest, but programming-wise is SOE all that fast?
def FindPrime(n): primes = [2, 3] for num in range(4, n): notprime = False for p in primes: if num % p == 0: notprime = True if notprime == False: primes.append(num) print primes print FindPrime(100)