Return all prime numbers smaller than M

后端 未结 9 2137
梦谈多话
梦谈多话 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:31

    The usual answer is to implement the Sieve of Eratosthenes, but this is really only a solution for finding the list of all prime numbers smaller than N. If you want primality tests for specific numbers, there are better choices for large numbers.

提交回复
热议问题