hdu 2013 蟠桃记

蟠桃记

 

题目分析:

很普通的一道函数题,利用所给的条件,进行过程的模拟,构造出一个函数

代码:

#include<iostream>
using namespace std;
int fun(int m)
{
    int sum = 0;
    if (m == 1)
    {
        return 1;
    }
    else{
        sum = 1;
        while (--m)
        {
            sum = 2 * (sum + 1);
        }
        return sum;
    }

}
int main()
{
    int n;
    while (cin >> n)
    {
        cout << fun(n) << endl;
    }

    system("pause");
    return 0;
}

 

posted @ 2020-02-08 01:46  PCDL&TIPO  阅读(123)  评论(0编辑  收藏  举报