python素數判斷方法?
python素數判斷操作如下:
mport timeit from math import sqrt def isPrimes1(n): if n <= 1: return False for i in range(2, int(sqrt(n) + 1)): if n % i == 0: return False return True def isPrimes2(n): if n > 1: if n == 2: return True if n % 2 == 0: return False for x in range(3, int(sqrt(n) + 1), 2): if n % x == 0: return False return True return False print(timeit.timeit("isPrimes1(100)", setup="from chapter01 import isPrimes1", number=10000)) print(timeit.timeit("isPrimes2(100)", setup="from chapter01 import isPrimes2", number=10000))
上一篇有哪些游戲攻略值得分享
下一篇怎樣電腦上遠程攝像頭監控