Guest User

Untitled

a guest
May 22nd, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. def output(l):
  2.     length = len(l)
  3.     for i in range(length-1):
  4.         print(l[i], end="+")
  5.     print(l[-1])
  6.  
  7. def decomposition(rest, previous=None, dec=[]):
  8.     current = dec[:]
  9.     if previous is None:
  10.         previous = rest
  11.     if rest == 0:
  12.         output(current)
  13.     else:
  14.         max_summand = min(rest, previous)
  15.         for i in range(max_summand, 0, -1):
  16.             current.append(i)
  17.             decomposition(rest - i, i, current)
  18.             current.pop()
  19.            
  20.  
  21. number = int(input())
  22. decomposition(number)
Advertisement
Add Comment
Please, Sign In to add comment