问题 C: 数的计数(number)
时间限制: 1 Sec 内存限制: 64 MB提交: 45 解决: 26
题目描述
我们要求找出具有下列性质数的个数(包含输入的自然数n),先输入一个自然数n(n≤1000),然后对此自然数按照如下方法进行处理:
(1)不作任何处理;
(2)在它的左边加上一个自然数,但该自然数不能超过原数的一半;
(3)加上数后,继续按此规则进行处理,直到不能再加自然数为止。
输入
一个正整数n。
输出
符合以上性质的数的个数。
样例输入
6
样例输出
6
提示
样例说明:满足条件的数为6,16,26,36,126,136。
#include <stdio.h>
int jishu(int n)
{
int s=1,i;
if(n==1)
return s;
else
{
for(i=1;i<=n/2;i++)
s+=jishu(i);
return s;
}
}
int main()
{
int n;
scanf("%d",&n);
printf("%d
",jishu(n));
return 0;
}