Why is Sieve of Eratosthenes more efficient than the simple “dumb” algorithm?

后端 未结 7 2018
遇见更好的自我
遇见更好的自我 2020-12-08 21:56

If you need to generate primes from 1 to N, the \"dumb\" way to do it would be to iterate through all the numbers from 2 to N and check if the numbers are divisable by any p

7条回答
  •  佛祖请我去吃肉
    2020-12-08 22:18

    Explained in this paper: http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf

    I think it's quite readable even without Haskell knowledge.

提交回复
热议问题