- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtopianTree.java
More file actions
Latest commit
54 lines (46 loc) · 1.45 KB
/
Copy pathUtopianTree.java
File metadata and controls
54 lines (46 loc) · 1.45 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
The Utopian Tree goes through 2 cycles of growth every year. Each spring, it doubles in height. Each summer, its height increases by 1 meter.
Laura plants a Utopian Tree sapling with a height of 1 meter at the onset of spring. How tall will her tree be after N growth cycles?
Input Format
The first line contains an integer, T, the number of test cases.
T subsequent lines each contain an integer, N, denoting 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 height must be printed on a new line.
*/
importjava.io.*;
importjava.util.*;
importjava.text.*;
importjava.math.*;
importjava.util.regex.*;
publicclassSolution {
publicstaticvoidmain(String[] args) {
Scannerin = newScanner(System.in);
intt = in.nextInt();
for(inta0 = 0; a0 < t; a0++){
intht=1;
intn = in.nextInt();
if(n==0)
{
System.out.println("1");
}
if(n>=1)
{
for(inti=1;i<=n;i++)
{
if(i%2!=0)
{
ht=ht*2;
}
else
{
ht=ht+1;
}
}
System.out.println(ht);
}
}
}
}