Description
有个人赶着鸭子去每个村庄卖,每经过一个村子卖去所赶鸭子的一半又2只。这样他经过了n个村子后还剩两只鸭子,问他出发时共赶多少只鸭子?
Input
输入有多组数据,每组数据占一行,包含唯一的正整数n.(0 < n <= 60).
Output
每组测试实例,输出一行,第一行输出出发时共赶了多少只鸭子。
AC Code
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
#define inf 0x3f3f3f3f
void yz(int n,long long s) //n可以到60,结果可能为long long
{
if(n==0) cout<<s<<endl;
else yz(n-1,(s+2)*2);
return;
}
int main(int argc, char** argv) {
int n;
while(cin>>n)
{
yz(n,2);
}
return 0;
}