Skip to content

Instantly share code, notes, and snippets.

@mmourafiq
Created August 27, 2012 18:59
Show Gist options
  • Save mmourafiq/3491346 to your computer and use it in GitHub Desktop.
Save mmourafiq/3491346 to your computer and use it in GitHub Desktop.
finding prime numbers less than x
def primes_less(x):
non_prime = set()
i = 2
while i*i <= x:
if i not in non_prime:
j = i
while j*i <= x:
non_prime.add(j*i)
j += 1
i += 1
return set(range(2, x+1)) - non_prime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment