Skip to content

Instantly share code, notes, and snippets.

@shieldsd
Created March 30, 2012 13:59
Show Gist options
  • Save shieldsd/2251729 to your computer and use it in GitHub Desktop.
Save shieldsd/2251729 to your computer and use it in GitHub Desktop.
Project Euler #23
from math import sqrt
def divisors(n):
for x in xrange(1, int(sqrt(n)) + 1):
if n % x == 0:
yield x
if x != 1 and x * x != n:
yield n / x
abundants = set()
def abundantsum(n):
if sum(divisors(n)) > n:
abundants.add(n)
if not any((n - a in abundants) for a in abundants):
return 0
return 1
print sum(n for n in range(1, 28124) if not abundantsum(n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment