-
Notifications
You must be signed in to change notification settings - Fork 694
/
Copy pathSolution.java
29 lines (25 loc) · 928 Bytes
/
Solution.java
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
//Problem: https://www.hackerrank.com/challenges/utopian-tree
//Java 8
import java.io.*;
import java.util.*;
import java.lang.Math;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner input = new Scanner(System.in);
int testCases = input.nextInt();
for(int i = 0; i < testCases; i++)
{
int cycles = input.nextInt();
//Calculates according the an equation defined by the arithmetico-geometric sequence
if(cycles % 2 == 0)
{
System.out.println((int) (Math.pow(2, cycles/2)*2) -1);
}
else
{
System.out.println((int) ((Math.pow(2, (cycles-1)/2)*2) -1)*2);
}
}
}
}