AC代码:
#include <iostream> #include <cstdio> using namespace std; int main(void) { freopen("in.txt","r",stdin); int n; while(scanf("%d",&n)!=EOF) { long long sum1,sum2,sum; sum1=3; sum2=8; if(n==1) sum=sum1; else if(n==2) sum=sum2; else for(int i=3;i<=n;i++) { sum=2*sum2+2*sum1; sum1=sum2; sum2=sum; } printf("%lld ",sum); } fclose(stdin); return 0; }