Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created January 1, 2012 21:53
Show Gist options
  • Save jakedobkin/1548446 to your computer and use it in GitHub Desktop.
Save jakedobkin/1548446 to your computer and use it in GitHub Desktop.
Euler 87
# 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