Skip to content

Instantly share code, notes, and snippets.

@GrAndSE
Created September 21, 2011 14:10
Show Gist options
  • Save GrAndSE/1232124 to your computer and use it in GitHub Desktop.
Save GrAndSE/1232124 to your computer and use it in GitHub Desktop.
Prime numbers searching using Python (with optimizations)
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