From ebdce3c59ab84140d522662f1ee6663276f21fcf Mon Sep 17 00:00:00 2001 From: Divya Chukkapalli <12871391+divya0795@users.noreply.github.com> Date: Tue, 17 Nov 2026 03:47:38 -0800 Subject: [PATCH] fix(maths): include index n in the eulers_totient sieve The sieve broke on i * primes[j] >= n, so index n was never updated and totient(n)[n] stayed n - 1 for every composite n (totient(10)[10] == 9, phi(10) == 4). Use > n so the last entry is sieved too. --- maths/eulers_totient.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/eulers_totient.py b/maths/eulers_totient.py index 00f0254c215a..27badfa4eb20 100644 --- a/maths/eulers_totient.py +++ b/maths/eulers_totient.py @@ -22,7 +22,7 @@ def totient(n: int) -> list: if is_prime[i]: primes.append(i) for j in range(len(primes)): - if i * primes[j] >= n: + if i * primes[j] > n: break is_prime[i * primes[j]] = False