Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- l = []
- num = int(input("Enter a number: "))
- def findCombinations(n, product):
- global l
- #Base condition
- if product == num:
- print(l)
- return
- for x in range(n, int(num/2)+1):
- #If product exceeds num -> return to last recursive call
- if product*x > num:
- return
- #Add number to product i.e. multiply
- product = product * x
- l.append(x)
- #Recursive call with same number
- findCombinations(x, product)
- #Backtrack
- l.pop()
- product = product//x
- findCombinations(2,1)
Advertisement
Add Comment
Please, Sign In to add comment