46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
import time
|
|
|
|
from sympy import divisors
|
|
|
|
|
|
def timer(func):
|
|
def wrapper(*args, **kwargs):
|
|
start_time = time.time()
|
|
result = func(*args, **kwargs)
|
|
end_time = time.time()
|
|
print(f"Execution time: {end_time - start_time:.6f} seconds")
|
|
return result
|
|
|
|
return wrapper
|
|
|
|
|
|
def is_abundant(n: int) -> bool:
|
|
return sum(divisors(n)) > 2 * n
|
|
|
|
|
|
def is_sum_of_two_abundants(n: int) -> bool:
|
|
if n < 24:
|
|
return False
|
|
for i in range(12, n // 2 + 1):
|
|
if is_abundant(i) and is_abundant(n - i):
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
|
|
@timer
|
|
def main():
|
|
limit = 28123
|
|
abundant_numbers = [n for n in range(1, limit + 1) if is_abundant(n)]
|
|
non_abundant_sums = set(range(1, limit + 1))
|
|
for i in range(len(abundant_numbers)):
|
|
for j in range(i, len(abundant_numbers)):
|
|
if abundant_numbers[i] + abundant_numbers[j] > limit:
|
|
break
|
|
non_abundant_sums.discard(abundant_numbers[i] + abundant_numbers[j])
|
|
print(sum(non_abundant_sums))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|