Created
February 7, 2011 10:31
-
-
Save krikulis/814225 to your computer and use it in GitHub Desktop.
Eulers sieve example in python
This file contains hidden or 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
# find sum of all non-prime numbers in range(100) | |
def eulers_sieve(n): | |
c = range(n+1) | |
fin = int(n**0.5) | |
for i in xrange(2, fin+1): | |
if not c[i]: | |
continue | |
c[2*i::i] = [None] * (n//i - 1) | |
return [i for i in c[2:] if i] | |
if __name__ == "__main__": | |
pirmsk_sum= sum(eulers_sieve(100)) | |
print sum(range(100)) - pirmsk_sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment