From e33113facc3d5130e286368542f97972bf79e334 Mon Sep 17 00:00:00 2001 From: filifa Date: Thu, 26 Jun 2025 10:55:42 -0400 Subject: [PATCH] simplify code a bit --- notebooks/problem0069.ipynb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/notebooks/problem0069.ipynb b/notebooks/problem0069.ipynb index f1ac654..069b77b 100644 --- a/notebooks/problem0069.ipynb +++ b/notebooks/problem0069.ipynb @@ -20,7 +20,7 @@ "Put simply, this means that smaller prime factors will lead to a larger $n/\\phi(n)$. These two facts suggest we should try numbers that are the product of the first several primes, which are called [primorials](https://en.wikipedia.org/wiki/Primorial). Our answer then is the largest primorial less than 1000000:\n", "$$2 \\times 3 \\times 5 \\times 7 \\times 11 \\times 13 \\times 17 = 510510$$\n", "\n", - "Alternatively, you can just ask SageMath - its implementation of $\\phi(n)$ is fast enough for this problem. However, you might run into difficulties writing your own implementation that's this fast." + "Alternatively, you can just ask SageMath - its implementation of $\\phi(n)$ is fast enough to brute force this problem. However, you might run into difficulties writing your own implementation that's this fast." ] }, { @@ -41,8 +41,7 @@ } ], "source": [ - "qs = {n: n/euler_phi(n) for n in range(1, 1000001)}\n", - "max(qs, key=qs.get)" + "max(range(1, 1000001), key=lambda n: n / euler_phi(n))" ] }, {