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 the spring. Its height is 1 meter. Can you find the height of the tree after N growth cycles?
Now, a new Utopian tree sapling is planted at the onset of the 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.
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
1 <= T <= 10
0 <= N <= 60
Output Format
For each test case, print the height of the Utopian tree after N cycles.
For each test case, print the height of the Utopian tree after N cycles.
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 | import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; /** * @author Rakesh KR */ public class Solution { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String numberOfTestCases = in.readLine(); if(numberOfTestCases.matches("[1-9]|10")){ for(int i=0;i<Integer.parseInt(numberOfTestCases);i++){ String num = in.readLine(); long val = Long.parseLong(num); if(val >=0 && val <=60){ int count = 0; for(int j=1 ;j<=val+1; j++){ count = (j%2==0) ? count * 2 : count + 1 ; } System.out.println(count); } } } } } |
Comments
Post a Comment