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

后端 未结 30 3232
遇见更好的自我
遇见更好的自我 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:47

    There are many ways to do the primality test.

    There isn't really a data structure for you to query. If you have lots of numbers to test, you should probably run a probabilistic test since those are faster, and then follow it up with a deterministic test to make sure the number is prime.

    You should know that the math behind the fastest algorithms is not for the faint of heart.

提交回复
热议问题