This Code is giving wrong output for n=2
and it is very slow.
How Can i make this code for finding as many positive distinct summands more efficient?
TASK- Represent a given positive integer n
as a sum of as many pairwise
distinct positive integers as possible.
OUTPUT: First Contains an integer k
.Second Line Contains k
positive distinct positive summands that sum up to n
.
Sample Input:
8
Output:
3
1 2 5
n=int(input())
p=[]
i=1
while(i<=n):
if (n-i) not in p:
p.append(i)
n-=i
i+=1
print(len(p))
print(*p)