1 parent 965b1ff commit 568425dCopy full SHA for 568425d
1 file changed
project_euler/problem_072/sol1.py
@@ -18,7 +18,7 @@
18
function, phi(n). So, the answer is simply the sum of phi(n) for 2 <= n <= 1,000,000
19
Sum of phi(d), for all d|n = n. This result can be used to find phi(n) using a sieve.
20
21
-Time: 3.5 sec
+Time: 1 sec
22
"""
23
24
@@ -36,8 +36,9 @@ def solution(limit: int = 1_000_000) -> int:
36
phi = [i - 1 for i in range(limit + 1)]
37
38
for i in range(2, limit + 1):
39
- for j in range(2 * i, limit + 1, i):
40
- phi[j] -= phi[i]
+ if phi[i] == i - 1:
+ for j in range(2 * i, limit + 1, i):
41
+ phi[j] -= phi[j] // i
42
43
return sum(phi[2 : limit + 1])
44
0 commit comments