显示代码纯文本
#include <cstring>
#include <iostream>
#include <cstdio>
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin ("hanoi.in");
ofstream fout ("hanoi.out");
string cheng(string x,string y)
{
int p[110]={0},q[110]={0},ans[110]={0};
string memeda;
int l1=x.length();
int l2=y.length();
for (int j=l1-1;j>=0;j--)
p[l1-j]=x[j]-'0';
for (int j=l2-1;j>=0;j--)
q[l2-j]=y[j]-'0';
for (int i=1;i<=l1;i++)
for (int j=1;j<=l2;j++)
{
ans[i+j-1]+=p[i]*q[j];
ans[i+j]+=ans[i+j-1]/10;
ans[i+j-1]%=10;
}
bool k=false;
for (int i=l1+l2,j=0;i>0;i--,j++)
{
if (ans[i]!=0)k=true;
if (k==true)memeda+=char(ans[i]+48);
}
return memeda;
}
int main()
{
int n;
string ans="2";
fin>>n;
while (n--)
{
ans=cheng(ans,"2");
}
int l=ans.length();
if (ans[l-1]>='2')ans[l-1]-=2;
else
{
ans[l-2]--;
ans[l-1]+=8;
}
fout<<ans;
return 0;
}