View Code of Problem 3692

#include<iostream>

using namespace std;


long long solve(int n){
    if(n==0) return 0;
    if(n==1) return 3;
     long long a[n];
     a[0]=3;
     a[1]=6;
     a[2]=6;
     for(int i=3;i<n;++i){
        a[i]=a[i-1]+2*a[i-2];
     }
     return a[n-1];
}

int main(){
   int n;
   while(cin>>n){
     cout<<solve(n)<<endl;
   }
   return 0;
}

Double click to view unformatted code.


Back to problem 3692