小编Shi*_*hiv的帖子

阿特金的筛子

我一直在努力学习生成素数的算法,我在维基百科上遇到了阿特金的Sieve.我理解算法的几乎所有部分,除了少数几个.以下是问题:

  1. 下面的三个二次方程如何形成?4x ^ 2 + y ^ 2,3x ^ 2 + y ^ 2和3x ^ 2-y2
  2. 维基百科中的算法讨论模数为60但我不明白在下面的psudocode中使用的方式/位置.
  3. 如何找到这些提醒1,5,7和11?

以下是维基百科的伪代码供参考:

// 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)

language-agnostic algorithm math primes sieve-of-atkin

18
推荐指数
2
解决办法
3560
查看次数