Created
September 21, 2011 14:10
-
-
Save GrAndSE/1232124 to your computer and use it in GitHub Desktop.
Prime numbers searching using Python (with optimizations)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def prime(num): | |
primes = [] | |
def is_prime(n): | |
limit = int(n**0.5) + 1 | |
for i in primes: | |
if i > limit: | |
return True | |
elif n % i == 0: | |
return False | |
return True | |
for i in range(2, num): | |
if is_prime(i): | |
primes.append(i) | |
return primes | |
print prime(1000000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment