Checking if an int is prime more efficiently

前端 未结 11 810
暗喜
暗喜 2020-12-11 04:20

I recently was part of a small java programming competition at my school. My partner and I have just finished our first pure oop class and most of the questions were out of

11条回答
  •  渐次进展
    2020-12-11 04:51

    Even faster than all of that is using the Miller-Rabin test. It's a probabilistic test, and therefore has a certain level of error; however, the test runs multiple times which shrinks that error as small as needed (50 often suffices for commercial applications).

    Not in Java, but here's a quick implementation in Python I cooked up.

提交回复
热议问题