Skip to content

Instantly share code, notes, and snippets.

@shieldsd
Created March 30, 2012 13:55
Show Gist options
  • Save shieldsd/2251712 to your computer and use it in GitHub Desktop.
Save shieldsd/2251712 to your computer and use it in GitHub Desktop.
Project Euler #21
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
def amicable(n):
m = sum(divisors(n))
if m != n and n == sum(divisors(m)):
return 1
return 0
print sum(x for x in range(10000) if amicable(x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment