Most efficient code for the first 10000 prime numbers?

前端 未结 30 1481
日久生厌
日久生厌 2020-11-29 19:09

I want to print the first 10000 prime numbers. Can anyone give me the most efficient code for this? Clarifications:

  1. It does not matter if your code is ineffici
30条回答
  •  清歌不尽
    2020-11-29 19:33

    Not efficient at all, but you can use a regular expression to test for prime numbers.

    /^1?$|^(11+?)\1+$/
    

    This tests if, for a string consisting of k1”s, k is not prime (i.e. whether the string consists of one “1” or any number of “1”s that can be expressed as an n-ary product).

提交回复
热议问题