找到次数之间的规律。
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
long long func(int n){
if(n == 1){
return 2;
}else{
return 3 * func(n-1) +2;
}
}
int main(){
int n;
long long ans;
while (cin >> n) {
ans = func(n);
cout << ans << endl;
}
return 0;
}
京公网安备 11010502036488号