from sets import Set from eulertools import sieve, cachesumdiv divisors = list(sieve(10000)) primes = Set(sieve(10000)) sumdivisors = lambda n: cachesumdiv(n, divisors)-n amicable = [] skips = Set() for n in range(1,10000): if n in skips or n in primes: continue sn = sumdivisors(n) if sn <= 10000 and sn != n and sumdivisors(sn) == n: amicable.append(n+sn) skips.add(sn) print sum(amicable)
from eulertools import sieve, cachesumdiv, fast_conjoin as conjoin from sets import Set from itertools import count primes = list(sieve(29000)) sumdivs = lambda n: cachesumdiv(n, primes) def abundants(): for i in count(1): if i > 28123: break sd = sumdivs(i) - i if sd > i: yield i abundants = list(abundants()) possibilities = [False]*28124 for i in abundants: for j in abundants: if i + j > 28123: break possibilities[i+j] = True sum = 0 for i in range(len(possibilities)): if not possibilities[i]: sum += i print sum