Ejemplo n.º 1
0
from tools import divisors

candidates = range(1, 10001)

n = 0
while candidates:
    a = candidates.pop(0)
    b = sum([_ for _ in divisors(a)])
    if b in candidates: candidates.remove(b)
    if a != b and a == sum([_ for _ in divisors(b)]):
        n += a + b

print n
Ejemplo n.º 2
0
def is_abundant(num):
    return sum(divisors(num)) > num
Ejemplo n.º 3
0
#!/usr/bin/env python

"""
Evaluate the sum of all the amicable numbers under 10000.
"""

from tools import divisors

N = 10**4
amicable = []
for n in xrange(2, N):
    if n in amicable: continue

    sum_divisors_n = sum(divisors(n))
    if sum_divisors_n != n and sum(divisors(sum_divisors_n)) == n \
      and sum_divisors_n < N:
        print "(%s, %s)" % (n, sum_divisors_n)
        amicable.extend([n, sum_divisors_n])

print sum(amicable)