2019-07-16 04:11:49 +02:00
|
|
|
from lib_misc import sum_proper_divisors
|
2015-11-16 20:56:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
def is_abundant(n):
|
2019-07-16 04:11:49 +02:00
|
|
|
return sum_proper_divisors(n) > n
|
2015-11-16 20:56:24 +01:00
|
|
|
|
|
|
|
|
2019-07-16 04:11:49 +02:00
|
|
|
def is_sum_of_two_abundant(n, abundant_numbers, abundant_numbers_set):
|
|
|
|
for a in abundant_numbers:
|
|
|
|
if a > n:
|
|
|
|
return False
|
|
|
|
d = n - a
|
|
|
|
if d in abundant_numbers_set:
|
|
|
|
return True
|
|
|
|
return False
|
2015-11-16 20:56:24 +01:00
|
|
|
|
|
|
|
|
2019-07-16 04:11:49 +02:00
|
|
|
def euler_023():
|
|
|
|
abundant_numbers = [n for n in range(1, 28123 + 1) if is_abundant(n)]
|
2015-11-16 20:56:24 +01:00
|
|
|
abundant_numbers_set = set(abundant_numbers)
|
2019-07-16 04:11:49 +02:00
|
|
|
return sum([n for n in range(1, 28123 + 1)
|
|
|
|
if not is_sum_of_two_abundant(n, abundant_numbers,
|
|
|
|
abundant_numbers_set)])
|
|
|
|
|
|
|
|
|
2015-11-16 20:56:24 +01:00
|
|
|
if __name__ == "__main__":
|
2019-07-16 04:11:49 +02:00
|
|
|
print("e023.py: {}".format(euler_023()))
|
|
|
|
assert(euler_023() == 4179871)
|