class Solution(object):
def getFactors(self, n):
"""
:type n: int
:rtype: List[List[int]]
"""
if n <= 1:
return []
res = []
i = 2
while i * i <= n:
if n % i == 0:
q = n / i
res.append([i, q])
subres = self.getFactors(q)
for r in subres:
if r[0] >= i:
res.append([i] + r)
i += 1
return res
Share simple Python solution


@IWantToPass
if r[0] >= i:
is used for checking and avoiding duplicates, for example whenn=24
, only[2,2,2,3]
should be recorded, not[2,3,2,2]