View Code of Problem 3692

#include<iostream>
using namespace std;

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

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

Double click to view unformatted code.


Back to problem 3692