Advertisement
Kamend1

Number

Aug 4th, 2023
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. def find_ways(N, current_way, current_sum, ways):
  2. if current_sum == N:
  3. ways.append(current_way)
  4. return
  5.  
  6. for num in range(1, N - current_sum + 1, 1):
  7. if not current_way or num <= current_way[-1]:
  8. find_ways(N, current_way + [num], current_sum + num, ways)
  9.  
  10.  
  11. N = int(input())
  12. ways = []
  13. find_ways(N, [], 0, ways)
  14.  
  15. for way in ways[::-1]:
  16. print(' + '.join(map(str, way)))
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement