A. Santa Claus and Candies
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Santa Claus has n candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all n candies he has.
Input
The only line contains positive integer number n (1 ≤ n ≤ 1000) — number of candies Santa Claus has.
Output
Print to the first line integer number k — maximal number of kids which can get candies.
Print to the second line k distinct integer numbers: number of candies for each of k kid. The sum of k printed numbers should be exactly n.
If there are many solutions, print any of them.
Examples
Input
5
Output
2
2 3
Input
9
Output
3
3 5 1
Input
2
Output
1
2
#include<stdio.h>
#define maxn 1000
int a[maxn];
void init();
int main()
{
init();
int n,i;
while(~scanf("%d",&n))
{
if(n==1||n==2)
{
printf("%d\n",1);
printf("%d\n",n);
continue;
}
printf("%d\n",a[n]);
int sum=0;
for(i=1;i<a[n];i++)
{
sum+=i;
printf("%d ",i);
}
printf("%d\n",n-sum);
}
return 0;
}
void init()
{
int s=1;
int i,j;
for(i=1;i<=1000;i+=s)
{
for(j=i;j<i+s+1;j++)
a[j]=s;
s++;
}///n分成若干个不相等的数
}
圣诞老人分糖果问题
本文介绍了一个关于圣诞老人如何将不同数量的糖果分配给最多数量的孩子的问题,并提供了一种算法解决方案。该问题要求每个孩子获得的糖果数量各不相同且为正整数。
461

被折叠的 条评论
为什么被折叠?



