Created
February 20, 2015 03:46
-
-
Save dineshrajpurohit/d643ef35a66737d769d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sieve of erosthenes | |
public static void primes(int n){ | |
Boolean[] prime = new Boolean[n+1]; | |
for(int i=2;i<=n;i++){ | |
prime[i] = true; | |
} | |
for(int div=2;div*div<=n;div++){ | |
if(prime[div] == true){ | |
for(int i=2*div;i<=n;i=i+div){ | |
prime[i] = false; | |
} | |
} | |
} | |
for(int i=2;i<=n;i++){ | |
if(prime[i]){ | |
System.out.print(i+ " "); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment