Return all prime numbers smaller than M

后端 未结 9 2158
梦谈多话
梦谈多话 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 Sieve of Eratosthenes is a good place to start.

    http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

提交回复
热议问题