From 928a4fe89a7185573d0a277584e3763d44685e62 Mon Sep 17 00:00:00 2001 From: Abhishek Singh Date: Tue, 22 Oct 2019 03:11:33 +0530 Subject: [PATCH] replaced 'j += i'with 'j += (2 * i)' --- Sieve of Eratosthenes/sieve.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sieve of Eratosthenes/sieve.cpp b/Sieve of Eratosthenes/sieve.cpp index a3a8362..fe7a861 100644 --- a/Sieve of Eratosthenes/sieve.cpp +++ b/Sieve of Eratosthenes/sieve.cpp @@ -8,9 +8,8 @@ void sieveOptimized(int N) { isPrime[i] = 1; for (int i = 2; i * i <= N; i++) { if (isPrime[i]) { - // For further optimization, You can do instead of j += i, j += (2 * i). // Proof is left to reader :) - for (int j = i * i; j <= N; j += i) + for (int j = i * i; j <= N; j += (2 * i)) isPrime[j] = 0; } }