Skip to content

Instantly share code, notes, and snippets.

@msalahi
Created September 15, 2011 14:22
Show Gist options
  • Save msalahi/1219358 to your computer and use it in GitHub Desktop.
Save msalahi/1219358 to your computer and use it in GitHub Desktop.
euler23
import math
import time
def isAbundant(n):
div = [1]
for i in range(2,int(math.sqrt(n))+1):
if n%i==0:
div += [i] if i==n/i else [i,n/i]
return True if sum(div)>n else False
def sumOfUniqueAbundantPairSums():
uniqueSums = []
total = 0
abundantNumbers = [n for n in xrange(1,28124) if isAbundant(n)]
return sum(set(a1+a2 for a1 in abundantNumbers for a2 in abundantNumbers if a1+a2<28124))
time1 = time.time()
answer= sum(xrange(1,28124))-sumOfUniqueAbundantPairSums()
time2 = time.time()
print "Solution 2: " , time2-time1
print "Answer: ",answer
#Answer is 4179871
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment