{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Slow bruteforce" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import functools\n", "import sympy\n", "\n", "\n", "@functools.lru_cache(maxsize=None)\n", "def aliquot_sum(n):\n", " return sympy.divisor_sigma(n) - n\n", "\n", "\n", "def is_amicable(n):\n", " return aliquot_sum(n) != n and aliquot_sum(aliquot_sum(n)) == n\n", "\n", "\n", "L = 10_000\n", "\n", "sum(n for n in range(2, L) if is_amicable(n))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.4" }, "title": "Amicable numbers" }, "nbformat": 4, "nbformat_minor": 2 }