View Code of Problem 3834

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int sum=0;
		sum+=pow(2,n);
		for(int i=2;i<=n;i+=2){
			int q=1,p=1;
			int w=n;
			int e=1;
			for(int j=0;j<i;j++){
				q*=w;
				w--;
			}
			for(int j=0;j<i;j++){
				p*=e;
				e++;
			}
			sum+=q/p*pow(2,n-i);
		}
		cout<<sum<<endl;
	} 
	return 0;
}

Double click to view unformatted code.


Back to problem 3834