74 lines
1.9 KiB
Plaintext
74 lines
1.9 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "22f94a3b",
|
|
"metadata": {},
|
|
"source": [
|
|
"# [Non-Abundant Sums](https://projecteuler.net/problem=23)\n",
|
|
"\n",
|
|
"Just like in [problem 21](https://projecteuler.net/problem=21), we'll define an `aliquot_sum` function and use that to find all the [abundant numbers](https://en.wikipedia.org/wiki/Abundant_number) below 28,124. Then we check every integer less than 28,124 to see if it's the sum of any two abundant numbers, and if it is, remove it from a set containing all those integers. Whatever's left in that set are the non-abundant sums."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "6747d2a3",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"4179871\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"aliquot_sum = lambda n: sigma(n) - n\n",
|
|
"\n",
|
|
"abundant_numbers = {k for k in range(1, 28124) if aliquot_sum(k) > k}\n",
|
|
"\n",
|
|
"non_abundant_sums = set(range(1, 28124))\n",
|
|
"for n in range(1, 28124):\n",
|
|
" for m in abundant_numbers:\n",
|
|
" if n - m in abundant_numbers:\n",
|
|
" non_abundant_sums.discard(n)\n",
|
|
" break\n",
|
|
"\n",
|
|
"print(sum(non_abundant_sums))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "91a43bd1",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Relevant sequences\n",
|
|
"* Numbers that are not the sum of two abundant numbers: [A048242](https://oeis.org/A048242)"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "SageMath 9.5",
|
|
"language": "sage",
|
|
"name": "sagemath"
|
|
},
|
|
"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.11.2"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|