#一般穷举
for i in range(2,num): if lst1[0] % i ==0:
#改进,//2或者//3。能减少至少一半的计算量
for i in range(2,num//2+1): if lst1[0] % i ==0:
#改进,sqrt(num)+1,然后根据对称性求出另一个因子。能减少90%的计算量!
for i in range(2,int(math.sqrt(num)+1)): if num % i ==0: ###both i and num//i are proper divisors
时间: 2024-10-11 20:51:34