更新时间:2023-11-28 14:09:40
从数组中的 n True
值开始,逐步将i
从3
枚举为sqrt(n)
的2
,如果数组中的第 i 个条目仍为True
,则将所有从i^2
到数组末尾的条目设置为2*i
到False
(这些将是i
的倍数).
Starting with n True
values in an array, with i
enumerated from 3
to sqrt(n)
by step of 2
, if ith entry in the array is still True
, set all entries from i^2
to the end of the array by step of 2*i
to False
(these will be the multiples of i
).
最后留在数组中的所有奇数True
条目都是素数.
All odd True
entries that are left in the array in the end, are prime.
所有找到的数字和 2 都是 n 下面存在的所有质数.
All thus found numbers, and 2, are all the prime numbers that exist below n.