Created
February 10, 2015 00:06
-
-
Save tolpp/246f9813c71d92bfd124 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
Sieve(n) | |
//Eratosthenes'in Eleği'nin implementasyonu | |
//Input: n > 1 olan n tamsayısı | |
//Output: n'den küçük veya n e eşit asal sayılar dizisi | |
for p←2 to n do A[p]←p | |
for p←2 to floor(sqrt(n)) do | |
if A[p] != 0 //daha önceki döngü içerisinde p elenmemişse | |
j ← p ∗ p | |
while j ≤ n do | |
A[j]←0 //j. elemanı elenmiş olarak işaretle | |
j ←j + p | |
//A dizisindeki elenmemiş elemanları asal sayı olarak L dizisine at | |
i ←0 | |
for p←2 to n do | |
if A[p] != 0 | |
L[i]←A[p] | |
i ←i + 1 | |
return L |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment