Skip to content

Instantly share code, notes, and snippets.

@tolpp
Created February 10, 2015 00:06
Show Gist options
  • Save tolpp/246f9813c71d92bfd124 to your computer and use it in GitHub Desktop.
Save tolpp/246f9813c71d92bfd124 to your computer and use it in GitHub Desktop.
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