开发者

Can binarysearch be used for checking primality?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜