How to create the most compact mapping n → isprime(n) up to a limit N?

后端 未结 30 3504
遇见更好的自我
遇见更好的自我 2020-11-22 02:11

Naturally, for bool isprime(number) there would be a data structure I could query.
I define the best algorithm, to be the algorithm that pr

30条回答
  •  感动是毒
    2020-11-22 02:43

    One can use sympy.

    import sympy
    
    sympy.ntheory.primetest.isprime(33393939393929292929292911111111)
    
    True
    

    From sympy docs. The first step is looking for trivial factors, which if found enables a quick return. Next, if the sieve is large enough, use bisection search on the sieve. For small numbers, a set of deterministic Miller-Rabin tests are performed with bases that are known to have no counterexamples in their range. Finally if the number is larger than 2^64, a strong BPSW test is performed. While this is a probable prime test and we believe counterexamples exist, there are no known counterexamples

提交回复
热议问题