Last active
December 23, 2017 12:33
-
-
Save tolpp/cef616c3668714091ca2 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 class Eratosthenes { | |
| static int[] Sieve(int n) { | |
| int[] A = new int[n + 1]; | |
| int[] L = new int[n + 1]; | |
| for (int p = 2; p < n; p++) A[p] = p; // ilk veriler atanıyor | |
| for (int p = 2; p < (int) Math.sqrt(n); p++) { | |
| if (A[p] != 0) { | |
| int j = p * p; | |
| while (j < n) { // asal sayının katları eleniyor | |
| A[j] = 0; | |
| j = j + p; | |
| } | |
| } | |
| } | |
| int i = 0; | |
| for (int p = 2; p < n; p++) { | |
| if (A[p] != 0) { | |
| L[i] = A[p]; | |
| i++; | |
| } | |
| } | |
| L = Arrays.copyOf(L, i); | |
| return L; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment