Return all prime numbers smaller than M

后端 未结 9 2129
梦谈多话
梦谈多话 2021-01-02 14:46

Given an integer M. return all prime numbers smaller than M.

Give a algorithm as good as you can. Need to consider time and space complexity.

9条回答
  •  粉色の甜心
    2021-01-02 15:53

    The Sieve of Atkin is also the best algorithm to implement in this case and it takes only O(N) operations and O(N) space. Please refer https://en.wikipedia.org/wiki/Sieve_of_Atkin for detailed explanation of the algorithm and pseudocode.

提交回复
热议问题