minor edits

This commit is contained in:
filifa 2025-07-19 20:47:26 -04:00
parent 4618a9fef4
commit f162f99963
1 changed files with 29 additions and 11 deletions

View File

@ -7,28 +7,46 @@
"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."
"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 (as in problem 21, we could instead use a sieve to compute the divisor sums)."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "84f3ad0c",
"metadata": {},
"outputs": [],
"source": [
"aliquot_sum = lambda n: sigma(n) - n\n",
"abundant_numbers = {k for k in range(1, 28124) if aliquot_sum(k) > k}"
]
},
{
"cell_type": "markdown",
"id": "d6586d17",
"metadata": {},
"source": [
"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": 2,
"id": "6747d2a3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4179871\n"
]
"data": {
"text/plain": [
"4179871"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"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",
@ -36,7 +54,7 @@
" non_abundant_sums.discard(n)\n",
" break\n",
"\n",
"print(sum(non_abundant_sums))"
"sum(non_abundant_sums)"
]
},
{