Amicable numbers
First read the problem description.
Slow bruteforce
import functools
import sympy
@functools.lru_cache(maxsize=None)
def aliquot_sum(n):
return sympy.divisor_sigma(n) - n
def is_amicable(n):
return aliquot_sum(n) != n and aliquot_sum(aliquot_sum(n)) == n
= 10_000
L
sum(n for n in range(2, L) if is_amicable(n))
31626
Source code of the solution(s):