且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

质数发生器解释?

更新时间:2023-11-28 14:09:40

从数组中的 n True值开始,逐步将i3枚举为sqrt(n)2,如果数组中的第 i 个条目仍为True,则将所有从i^2到数组末尾的条目设置为2*iFalse(这些将是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.