Created
November 17, 2015 08:37
-
-
Save hagun/3dcb059da0018330ce19 to your computer and use it in GitHub Desktop.
에라토스테네스의 체
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
| public void prime() { | |
| long startAt = System.currentTimeMillis(); | |
| long max = 100000L; | |
| SortedSet<Long> arr = new TreeSet<>(); | |
| for (long i = 2 ; i < max ; i++) { | |
| arr.add(new Long(i)); | |
| } | |
| long last = 0L; | |
| do { | |
| Long prime = arr.first(); | |
| System.out.println("prime : " + prime); | |
| last = prime; | |
| arr.remove(prime); | |
| Long i = 2L; | |
| Long notPrime = 0L; | |
| do { | |
| notPrime = prime * i; | |
| arr.remove(notPrime); | |
| i++; | |
| } while(notPrime < max); | |
| } while(arr.size() != 0); | |
| long endAt = System.currentTimeMillis(); | |
| System.out.println(endAt - startAt); | |
| System.out.println(last); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment