@@ -0,0 +1,1746 @@
+#!/usr/bin/env python%0A#-*-coding:utf-8-*-%0A%0A'''%0AA perfect number is a number for which%0Athe sum of its proper divisors is exactly equal to the number.%0AFor example, the sum of the proper divisors of 28 would be%0A1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.%0A%0AA number n is called deficient if the sum of its proper divisors is%0Aless than n and it is called abundant if this sum exceeds n.%0A%0AAs 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16,%0Athe smallest number that can be written as the sum of two abundant numbers is 24.%0ABy mathematical analysis, it can be shown that%0Aall integers greater than 28123 can be written as the sum of two abundant numbers.%0AHowever, this upper limit cannot be reduced any further by analysis%0Aeven though it is known that the greatest number that cannot be expressed%0Aas the sum of two abundant numbers is less than this limit.%0A%0AFind the sum of all the positive integers which cannot be written%0Aas the sum of two abundant numbers.%0A'''%0A%0Afrom math import sqrt%0Aimport timeit%0A%0Adef get_divisor(n):%0A    d = %5B1%5D%0A    for i in range(2, int(sqrt(n)+1)):%0A        if i*i == n:%0A            d.append(i)%0A        elif n %25 i == 0:%0A            d.append(i)%0A            d.append(n/i)%0A    return d%0A%0Adef sum_of_two(n, a, c):%0A    for i in a:%0A        if i %3E n / 2:%0A            break%0A        if c%5Bn - i%5D:%0A            return True%0A    return False%0A%0Adef calc(n):%0A    c = %5BFalse%5D * (n + 1)%0A    for i in range(1, n+1):%0A        if sum(get_divisor(i)) %3E i:%0A            c%5Bi%5D = True%0A    a = %5Bi for i in range(n+1) if c%5Bi%5D%5D%0A    return sum(%5Bi for i in range(1, n+1) if not sum_of_two(i, a, c)%5D)%0A%0A%0Aif __name__ == '__main__':%0A    print calc(28123)%0A    print timeit.Timer('problem_023.calc(28123)', 'import problem_023').timeit(1)%0A

add problem 23