Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Uses python3
- import sys
- def optimal_summands(n):
- summands = []
- # write your code here
- k = n
- l = 1
- # straight forward implementation of the hint
- # we could also do a recursive call but the grader gives me an wrong format index out of bond exception
- while k > 2 * l:
- summands.append(l)
- k -= l
- l += 1
- summands.append(k)
- return summands
- if __name__ == '__main__':
- user_input = sys.stdin.read()
- n = int(user_input)
- summands = optimal_summands(n)
- print(len(summands))
- for x in summands:
- print(x, end=' ')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement