Guest User

Untitled

a guest
Mar 14th, 2022
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. l = []
  2. num = int(input("Enter a number: "))
  3.  
  4. def findCombinations(n, product):
  5.     global l
  6.    
  7.     #Base condition
  8.     if product == num:
  9.         print(l)
  10.         return
  11.  
  12.     for x in range(n, int(num/2)+1):
  13.         #If product exceeds num -> return to last recursive call
  14.         if product*x > num:
  15.             return
  16.        
  17.         #Add number to product i.e. multiply    
  18.         product = product * x
  19.         l.append(x)
  20.        
  21.         #Recursive call with same number
  22.         findCombinations(x, product)
  23.  
  24.         #Backtrack
  25.         l.pop()
  26.         product = product//x
  27.  
  28. findCombinations(2,1)
Advertisement
Add Comment
Please, Sign In to add comment