Factorization
franklinqin0 DFS
# Input & Output
@param n: an integer
@return: a list of combination
1
2
2
# Solution
# DFS
from math import sqrt
def getFactors(self, n):
res = []
def dfs(index, n, path):
if len(path) != 0:
res.append(path[:] + [n])
for i in range(index, int(sqrt(n)) + 1):
if n % i == 0:
path.append(i)
dfs(i, n//i, path)
path.pop()
dfs(2, n, [])
return res
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15