From 2a03f08eb085fcb5389f3b7c1ae6ddb64c13f5a1 Mon Sep 17 00:00:00 2001 From: Samiksha Kapoor Date: Tue, 22 Oct 2019 14:37:37 +0530 Subject: [PATCH] updated sieve --- JAVA/sieveerath | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/JAVA/sieveerath b/JAVA/sieveerath index b0f0c8f..de56dbb 100644 --- a/JAVA/sieveerath +++ b/JAVA/sieveerath @@ -3,7 +3,7 @@ class SieveOfEratosthenes { - void sieveOfEratosthenes(int n) + public void sieveOfEratosthenes(int n) { // Create a boolean array "prime[0..n]" and initialize // all entries it as true. A value in prime[i] will @@ -15,10 +15,10 @@ class SieveOfEratosthenes for(int p = 2; p*p <=n; p++) { // If prime[p] is not changed, then it is a prime - if(prime[p] == true) + if(prime[p]) { // Update all multiples of p - for(int i = p*p; i <= n; i += p) + for(int i = p*p; i <= n; i =i+2*p) prime[i] = false; } }