开发者

Can binarysearch be used for checking primality?

开发者 https://www.devze.com 2023-04-08 17:03 出处:网络
I wonder if binary search can be used to check whethe开发者_开发百科r a number is prime , Since the real question is can I find a number which is divisble other than the number itself and 1, and there

I wonder if binary search can be used to check whethe开发者_开发百科r a number is prime , Since the real question is can I find a number which is divisble other than the number itself and 1, and therefore I can imagine looking through an array of ordered integers from 2 to i/2 (i being a number being checked).......


Obviously not.

Binary search is a method of dividing the interval to two (almost) equal parts and decide which one contains the search value.

Testing any number to see whether it is a divisor doesn't tell you anything about which interval to choose.

0

精彩评论

暂无评论...
验证码 换一张
取 消