**Problem Statement :** The Utopian Tree goes through 2 cycles of growth every year. The first growth cycle occurs during the spring, when it doubles in height. The second growth cycle occurs during the summer, when its height increases by 1 meter. Now, a new Utopian Tree sapling is planted at the onset of spring. Its height is 1 meter. Can you find the height of the tree after N growth cycles?

**Input Format :** The first line contains an integer, T, the number of test cases. T lines follow; each line contains an integer, N, that denotes the number of cycles for that test case.

Constraints

1<=T<=10

0<=N<=60

**Output Format :** For each test case, print the height of the Utopian Tree after N cycles. Each line thus has to contain a single integer, only.

Sample Input

3

0

1

4

Sample Output

1

2

7

**Explanation:** There are 3 test cases. In the first case (N=0), the initial height (1) of the tree remains unchanged.

In the second case (when N = 1, i.e. after the 1st cycle), the tree doubles its height as it’s planted at the onset of spring. In the third case (N=4), the tree first doubles its height (2), then grows a meter (3), then doubles again (6), before growing another meter; at the end of the 4th cycle, its height is 7 meters.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | /*Utopian Tree*/ #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> void calculate_height(int n) { int sum=1,i; if(n==0) { printf("%d\n",1); return;} if(n>=1 && n<=60) { for(i=0;i<n;i++) { if(i%2==0) {sum= 2*sum;} else {sum=sum+1;} } printf("%d\n",sum); return; } } int main() { int t,n,i; scanf("%d",&t); if(t>=1 && t<=10) for(i=0;i<t;i++) { scanf("%d",&n); calculate_height(n); } return 0; } |

## Leave a Reply