Last active
August 22, 2016 04:03
-
-
Save mhtsai1010/c5f7e51c6095f0a33fcf to your computer and use it in GitHub Desktop.
Python: generate a prime list < n
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
#!/usr/bin/env python2 | |
# -*- coding: utf-8 -*- | |
def primes(n): | |
""" Returns a list of primes < n """ | |
sieve = [True] * n | |
for i in xrange(3,int(n**0.5)+1,2): | |
if sieve[i]: | |
sieve[i*i::2*i]=[False]*((n-i*i-1)/(2*i)+1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment