minor edits
This commit is contained in:
parent
4618a9fef4
commit
f162f99963
|
@ -7,28 +7,46 @@
|
||||||
"source": [
|
"source": [
|
||||||
"# [Non-Abundant Sums](https://projecteuler.net/problem=23)\n",
|
"# [Non-Abundant Sums](https://projecteuler.net/problem=23)\n",
|
||||||
"\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",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"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",
|
"id": "6747d2a3",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"data": {
|
||||||
"output_type": "stream",
|
"text/plain": [
|
||||||
"text": [
|
"4179871"
|
||||||
"4179871\n"
|
]
|
||||||
]
|
},
|
||||||
|
"execution_count": 2,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"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",
|
"non_abundant_sums = set(range(1, 28124))\n",
|
||||||
"for n in range(1, 28124):\n",
|
"for n in range(1, 28124):\n",
|
||||||
" for m in abundant_numbers:\n",
|
" for m in abundant_numbers:\n",
|
||||||
|
@ -36,7 +54,7 @@
|
||||||
" non_abundant_sums.discard(n)\n",
|
" non_abundant_sums.discard(n)\n",
|
||||||
" break\n",
|
" break\n",
|
||||||
"\n",
|
"\n",
|
||||||
"print(sum(non_abundant_sums))"
|
"sum(non_abundant_sums)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue