View Code of Problem 3834

#include<iostream>
#include<math.h>
using namespace std;
//阶乘
int fac(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return x * fac(x - 1);
	}
}
//排列
int A(int m, int n) {
	return fac(m) / fac(m - n);
}
//组合
int C(int m, int n) {
	return A(m, n) / fac(n);
}
int fun(int n, int x) {
	int another = n - x;
	return C(n, x)*(int)pow(2, n - x);
}

int main() {
	int n;
	while (cin >> n) {
		int sum = 0;
		for (int i = 0;i <= n;i += 2) {
			sum += fun(n, i);
		}
		printf("%d\n", sum);
	}
}

Double click to view unformatted code.


Back to problem 3834