其他分享
首页 > 其他分享> > 数的计算、

数的计算、

作者:互联网

洛谷1028 数的计算
本题地址: http://www.luogu.org/problem/show?pid=1028

题目描述
  我们要求找出具有下列性质数的个数(包含输入的自然数n):
  先输入一个自然数n(n<=1000),然后对此自然数按照如下方法进行处理:
  1.不作任何处理;
  2.在它的左边加上一个自然数,但该自然数不能超过原数的一半;
  3.加上数后,继续按此规则进行处理,直到不能再加自然数为止.
输入输出格式
输入格式:
一个自然数n(n<=1000)

输出格式:
一个整数,表示具有该性质数的个数。

输入输出样例
输入样例#1:
6
输出样例#1:
6
说明
满足条件的数为
6,16,26,126,36,136

#include<iostream>
#include<algorithm>
using namespace std;
int f[1010];
int main()
{
    int n;
    cin>>n;
    f[1]=1; 
    for (int i=2; i<=n; i++)
        f[i]=f[i-1]+f[i/2]+1;
        cout<<f[n]-f[n-1]<<endl;
}

标签:int,自然数,样例,计算,格式,include,输入
来源: https://blog.csdn.net/qq_51730338/article/details/120759808