rephrase
This commit is contained in:
parent
849441f151
commit
9671d506bd
|
@ -50,7 +50,7 @@
|
|||
"id": "8e268820",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"If you try to implement the totient function yourself, you might find it difficult to make this approach fast enough. An alternative is to sieve the values of totient - see [problem 70](https://projecteuler.net/problem=70). However, there's a few more *very* interesting methods to compute totient sums.\n",
|
||||
"If you try to implement the totient function yourself, you might find it difficult to make this approach fast enough. An alternative is to \"sieve\" the values of totient - see [problem 70](https://projecteuler.net/problem=70). However, there's a few more *very* interesting methods to compute totient sums.\n",
|
||||
"\n",
|
||||
"## Recursive totient sum\n",
|
||||
"\n",
|
||||
|
@ -159,7 +159,7 @@
|
|||
"\n",
|
||||
"$$M(n) = 1 + \\lfloor b\\rfloor M(\\lfloor a\\rfloor) - \\sum_{x=1}^a \\mu(x)\\left\\lfloor \\frac{n}{x}\\right\\rfloor - \\sum_{y=2}^b M\\left(\\left\\lfloor \\frac{n}{y}\\right\\rfloor\\right)$$\n",
|
||||
"\n",
|
||||
"Now we have a recursive implementation of $M(n)$. All that's left is to calculate the values of $\\mu(n)$ that we need. We can do this with a sieve, since $\\mu$ is a [multiplicative function](https://en.wikipedia.org/wiki/Multiplicative_function)."
|
||||
"Now we have a recursive implementation of $M(n)$. All that's left is to calculate the values of $\\mu(n)$ that we need. By taking advantage of $\\mu$ being [multiplicative](https://en.wikipedia.org/wiki/Multiplicative_function), we can compute values using a similar strategy to the sieve of Eratosthenes - see [problem 10](https://projecteuler.net/problem=10)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -169,9 +169,7 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from math import isqrt\n",
|
||||
"\n",
|
||||
"def mobius_sieve(limit):\n",
|
||||
"def mobius_range(limit):\n",
|
||||
" ms = [n for n in range(0, limit)]\n",
|
||||
"\n",
|
||||
" for n in range(0, limit):\n",
|
||||
|
@ -193,7 +191,7 @@
|
|||
"id": "f12a8b30",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"We'll use $a = \\sqrt{1000000} = 1000$ as our upper bound on the sieve."
|
||||
"We'll use $a = \\sqrt{1000000} = 1000$ as our upper bound."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -203,7 +201,8 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"mu = list(mobius_sieve(isqrt(1000000) + 1))"
|
||||
"from math import isqrt\n",
|
||||
"mu = list(mobius_range(isqrt(1000000) + 1))"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue