我一直在努力学习生成素数的算法,我在维基百科上遇到了阿特金的Sieve.我理解算法的几乎所有部分,除了少数几个.以下是问题:
以下是维基百科的伪代码供参考:
// arbitrary search limit
limit ? 1000000
// initialize the sieve
for i in [5, limit]: is_prime(i) ? false
// put in candidate primes:
// integers which have an odd number of
// representations by certain quadratic forms
for (x, y) in [1, ?limit] × [1, ?limit]:
n ? 4x²+y²
if (n ? limit) and (n mod 12 = 1 or …Run Code Online (Sandbox Code Playgroud)