Advertisement
Guest User

Untitled

a guest
May 22nd, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 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, current=[]):
  8.     if previous is None:
  9.         previous = rest
  10.     if rest == 0:
  11.         output(current)
  12.     else:
  13.         max_summand = min(rest, previous)
  14.         for i in range(max_summand, 0, -1):
  15.             current.append(i)
  16.             decomposition(rest - i, i, current)
  17.             current.pop()
  18.            
  19.  
  20. number = int(input())
  21. decomposition(number)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement