How do I generate Primes Using 6*k +- 1 rule

前端 未结 7 1411
离开以前
离开以前 2021-02-04 02:07

We know that all primes above 3 can be generated using:

6 * k + 1
6 * k - 1

However we all numbers generated from the above formulas are not pr

相关标签:
7条回答
  • 2021-02-04 03:03

    Can this approach be much more optimized?

    The answer is yes.

    I'll start by saying that it is a good idea to use the sieve on a subset of number within a certain range, and your suggesting is doing exactly that.

    Reading about generating Primes:

    ...Furthermore, based on the sieve formalisms, some integer sequences (sequence A240673 in OEIS) are constructed which they also could be used for generating primes in certain intervals.

    The meaning of this paragraph is that your approach of starting with a reduced list of integers was indeed adopted by the academy, but their techniques are more efficient (but also, naturally, more complex).

    0 讨论(0)
提交回复
热议问题