From ef2d0423c26c390b001fbba4844dca4c67f27855 Mon Sep 17 00:00:00 2001 From: Daniele Fucini Date: Wed, 7 Jun 2023 17:02:08 +0200 Subject: [PATCH] Fix bug in sieve function --- Python/projecteuler.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Python/projecteuler.py b/Python/projecteuler.py index 032a091..ca53fe2 100644 --- a/Python/projecteuler.py +++ b/Python/projecteuler.py @@ -77,13 +77,10 @@ def sieve(n): # 0 and 1 are not prime, 2 and 3 are prime. primes[0] = 0 primes[1] = 0 -# primes[2] = 1 -# primes[3] = 1 # Cross out (set to 0) all even numbers and set the odd numbers to 1 (possible prime). - for i in range(4, n - 1, 2): + for i in range(4, n, 2): primes[i] = 0 -# primes[i+1] = 1 # If i is prime, all multiples of i smaller than i*i have already been crossed out. # if i=sqrt(n), all multiples of i up to n (the target) have been crossed out. So