什么是检查给定大数是否为质数的最快方法?我说的是约为10 ^ 32大小的数字。我尝试了MarcoBonelli大神在Stackoverflow上的算法,它是:
from math import sqrt; from itertools import count, islice
def isPrime(n):
return n > 1 and all(n%i for i in islice(count(2), int(sqrt(n)-1)))
但当用于大数字时,它会产生Stop argument for islice() must be None or an integer: 0 <= x <= sys.maxsize
错误。那么有没有其他不同且更快的方法呢?