-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutopian_tree.java
More file actions
45 lines (34 loc) · 1.07 KB
/
utopian_tree.java
File metadata and controls
45 lines (34 loc) · 1.07 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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
//https://www.hackerrank.com/challenges/utopian-tree
public class utopian_tree {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int test = in.nextInt();
int testcount = 0;
List<Integer> output = new ArrayList<Integer>();
while (testcount < test){
testcount++;
int number = in.nextInt();
int num_count = 0;
int growth = 0;
while (num_count<= number) {
if(num_count == 0){
growth = 1;
}else if(num_count%2 != 0){
growth = growth * 2;
}else if(num_count%2 == 0){
growth = growth + 1;
}
num_count++;
}
output.add(growth);
}
for(int i = 0; i < output.size(); i++) {
System.out.println(output.get(i));
}
}
}