Skip to content

Instantly share code, notes, and snippets.

@tayadehritik
Created January 30, 2018 09:42
Show Gist options
  • Select an option

  • Save tayadehritik/57de2dd5b3e91b3ed7017712e2347750 to your computer and use it in GitHub Desktop.

Select an option

Save tayadehritik/57de2dd5b3e91b3ed7017712e2347750 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int p(int, int);
int main()
{
int x, n;
cin>>n;
cin>>x;
int be =2;
int s=0;
int power = 2;
for(int i=0;i<n;i++){
if(i%2==0){
int something = p(x,power);
s = s+(something/be);
be =be +2;
power++;
}
else{
if(i==0){
cout<<"1";
s = s+1;
}
else{
int placeholder = p(x,power);
power++;
s = s+(placeholder/be);
be = be=2;
}
}
}
cout<<s;
return 0;
}
int p(int a,int b){
int res = a;
for(int i=0;i<(b-1);i++){
res = res + res;
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment