Created
January 30, 2018 10:20
-
-
Save tayadehritik/64acb6b12652a60689c298ab6c578e26 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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){ | |
| if(i==0){ | |
| s = s+1; | |
| } | |
| else{ | |
| int something = p(x,power); | |
| power++; | |
| s = s-(something/be); | |
| be = be +2; | |
| } | |
| } | |
| 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