def solve(): longestLength = 0 smallestMember = None seen = set() sieve(10**6) for n in xrange(2, 1000001): if n in seen: continue chainIndices = {n: 0} i = 0 while n > 1: n = aliquot(n) i += 1 if n > 1000000: break # This ^^ technically doesn't comply with a _prima facie_ # interpretation of the problem, but it makes the program terminate # in under a minute with the correct answer, so... if n in chainIndices: i2 = chainIndices[n] if i - i2 > longestLength: chain = [m for m,j in chainIndices.iteritems() if j >= i2] if all(m <= 1000000 for m in chain): longestLength = i - i2 smallestMember = min(chain) break elif n in seen: break seen.add(n) chainIndices[n] = i return smallestMember
def solve(): n = 28123 sieve(n+1) summable = set() abundant = [] for i in xrange(1, n+1): if aliquot(i) > i: abundant.append(i) summable.update(i+j for j in abundant if i+j <= n) return n*(n+1) // 2 - sum(summable)
def solve(): sieve(10000) cache = {} accum = 0 for i in xrange(2, 10001): j = aliquot(i) if j < i and cache.get(j) == i: accum += i + j elif j > i: cache[i] = j return accum