Created
October 19, 2014 22:12
-
-
Save MLLeKander/0a3ab76d526109b95c7c to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes Implementation
This file contains hidden or 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
class Sieve { | |
public static void main(String[] args) { | |
int MAX_VALUE = 10000; | |
boolean[] isComposite = new boolean[MAX_VALUE]; | |
isComposite[1] = isComposite[0] = true; | |
for (int i = 2; i*i < MAX_VALUE; i++) { | |
if (!isComposite[i]) { | |
for (int o = i*2; o < MAX_VALUE; o += i) { | |
isComposite[o] = true; | |
} | |
} | |
} | |
for (int i = 0; i < MAX_VALUE; i++) { | |
System.out.println(i+": "+!isComposite[i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment