我们要求找出具有下列性质数的个数(包含输入的自然数n):
先输入一个自然数n(n<=1000),然后对此自然数按照如下方法进行处理:
1. 不作任何处理;
2. 在它的左边加上一个自然数,但该自然数不能超过原数的一半;
3. 加上数后,继续按此规则进行处理,直到不能再加自然数为止.
输入描述 Input Description一个数n
输出描述 Output Description满足条件的数的个数
样例输入 Sample Input6
样例输出 Sample Output6
数据范围及提示 Data Size & Hint6个数分别是:
6
16
26
126
36
136
#include <iostream>
#include<algorithm>
using namespace std;
int n;
int counter = 0;void judge(int x)
{if (x==1){counter++;return;}counter++;for (int i=1;i<=x/2;i++)judge(i);
}int main()
{cin >> n;judge(n);cout << counter;cin >> n;return 0;}
本文发布于:2024-01-28 06:38:07,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17063950915516.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |