41 lines
1.0 KiB
Python
41 lines
1.0 KiB
Python
import math
|
|
|
|
|
|
def get_proper_divisors(n):
|
|
proper_divisors = set([1])
|
|
for i in range(2, int(math.sqrt(n)) + 1):
|
|
if n % i == 0:
|
|
proper_divisors.add(i)
|
|
proper_divisors.add(n / i)
|
|
return proper_divisors
|
|
|
|
|
|
def is_abundant(n):
|
|
return sum(get_proper_divisors(n)) > n
|
|
|
|
|
|
def get_abundant_numbers_smaller(n):
|
|
ret = []
|
|
for i in range(1, n):
|
|
if is_abundant(i):
|
|
ret.append(i)
|
|
return ret
|
|
|
|
|
|
def is_sum_of_two_abundant(n, abundant_numbers):
|
|
abundant_numbers_set = set(abundant_numbers)
|
|
for a1 in abundant_numbers:
|
|
if a1 > n:
|
|
return False
|
|
elif (n - a1) in abundant_numbers_set:
|
|
return True
|
|
|
|
|
|
if __name__ == "__main__":
|
|
abundant_numbers = get_abundant_numbers_smaller(30000)
|
|
cannot_be_written_as_sum_of_abundant = []
|
|
for i in range(28129):
|
|
if not is_sum_of_two_abundant(i, abundant_numbers):
|
|
cannot_be_written_as_sum_of_abundant.append(i)
|
|
print(sum(cannot_be_written_as_sum_of_abundant))
|