הנפה של ארטוסתנס – הבדלי גרסאות
תוכן שנמחק תוכן שנוסף
←קוד לנפת ארטוסתנס בשפת פייתון: כמו שכתוב בערך, מספיק לרוץ עד השורש |
|||
שורה 42:
==פסאודו קוד של נפת ארטוסתנס==
<syntaxhighlight lang="text">
algorithm Sieve of Eratosthenes is
input: an integer n > 1.
output: all prime numbers from 2 through n.
let A be an array of Boolean values, indexed by integers 2 to n,
for i = 2, 3, 4, ..., not exceeding √n do
for j = i2, i2+i, i2+2i, i2+3i, ..., not exceeding n do
return all i such that A[i] is true.
▲ If b[i] == 1 then
▲ b[j] := 0.
</syntaxhighlight>
|