Problem Description 约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下、由小到大顺序串着由64个圆盘构成的塔。目的是将最左边杆上的盘全部移到右边的杆上,条件是一次只能移动一个盘,且不允许大盘放在小盘的上面。
Input 包含多组数据,每次输入一个N值(1<=N=35)。
Output 对于每组数据,输出移动最小的次数。
Sample Input 1 3 12
Sample Output 2 26 531440 |
#include<iostream>
using namespace std;
int main (){
int n;
long long int a[36]={2}; // 会超出int 范围
for (int i=1;i<=35;i++)
a[i]=3*a[i-1]+2;
while (cin>>n){
cout<<a[n-1]<<endl;
}return 0;
}