帮同学做道题....其实真没什么好的做法....
1 def getList(n):
2 result = []
3 count = 3
4 max = n
5 while max%2 == 0:
6 max /= 2
7 result.append(2)
8
9 while count <= max:
10 if max%count == 0:
11 result.append(count)
12 max /= count
13 else:
14 count += 2
15 return result
16
2 result = []
3 count = 3
4 max = n
5 while max%2 == 0:
6 max /= 2
7 result.append(2)
8
9 while count <= max:
10 if max%count == 0:
11 result.append(count)
12 max /= count
13 else:
14 count += 2
15 return result
16
17 print getList(600851475143)
本文提供了一种质因数分解的实现方式,通过定义函数 `getList` 来获取指定整数的所有质因数。该算法首先去除所有偶数因数,然后从3开始递增检查奇数是否为因数。
965

被折叠的 条评论
为什么被折叠?



