Created
December 9, 2011 23:21
-
-
Save jakedobkin/1453787 to your computer and use it in GitHub Desktop.
Euler 47- modified sieve method in python
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
# set up 2 sieves- one is erastosthenes, the other is to track count | |
n=200000 | |
myPrimes = [True]*(n+1) | |
myCount = [0]*(n+1) | |
# sieve, but count each time each composite number is hit during sieve | |
for i in range (2,n): | |
if myPrimes[i] == True: | |
j = 2*i | |
while j<=n: | |
myPrimes[j]=False | |
myCount[j]+=1 | |
j=j+i | |
# count up runs of numbers with 4 factors- when you get to 4, stop | |
count = 0 | |
for k in range (2,len(myCount)-1): | |
if myCount[k]==4: | |
count += 1 | |
else: | |
count = 0 | |
if count == 4: | |
print "answer is %r" % (k-3) | |
break |
djacobs
commented
Dec 10, 2011
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment