Created
January 1, 2012 21:53
-
-
Save jakedobkin/1548446 to your computer and use it in GitHub Desktop.
Euler 87
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
# http://projecteuler.net/problem=87 | |
# set up prime sieve to 50MM**.25 | |
n=7100 | |
myPrimes = [True]*(n+1) | |
last = 0 | |
for i in range (2,n): | |
if myPrimes[i] == True: | |
j = 2*i | |
while j<=n: | |
myPrimes[j]=False | |
j=j+i | |
# dump sieve to list | |
primelist = [] | |
for k in range (2,n): | |
if myPrimes[k] == True: | |
primelist.append(k) | |
# brute force | |
primeset = set() | |
for c in range (0,23): | |
for b in range (0,73): | |
for a in range (0,908): | |
prime = primelist[a]**2 + primelist[b]**3 + primelist[c]**4 | |
if prime < 50000000: | |
# print a,b,c,prime | |
primeset.add(prime) | |
print len(primeset) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment