#Skip to menu

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


L = 10_000

sum(n for n in range(2, L) if is_amicable(n))
31626

Source code of the solution(s):