2017-03-10 01:10:37 -06:00
|
|
|
// Author: Rodney Shaghoulian
|
2018-07-27 16:45:56 -07:00
|
|
|
// Github: github.com/RodneyShag
|
|
|
|
|
// HackerRank: hackerrank.com/RodneyShag
|
2017-03-10 01:10:37 -06:00
|
|
|
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
2017-04-05 18:42:35 -05:00
|
|
|
// Time Complexity: O(N + T)
|
2017-03-10 01:10:37 -06:00
|
|
|
// Space Complexity: O(N + T)
|
|
|
|
|
public class Solution {
|
2017-09-11 09:32:17 -07:00
|
|
|
public static void main(String[] args) {
|
2017-04-05 18:42:35 -05:00
|
|
|
/* Save input */
|
2017-03-10 01:10:37 -06:00
|
|
|
Scanner scan = new Scanner(System.in);
|
|
|
|
|
int T = scan.nextInt();
|
|
|
|
|
int [] testcase = new int[T];
|
|
|
|
|
for (int i = 0; i < T; i++) {
|
|
|
|
|
testcase[i] = scan.nextInt();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Calculate answers for all T testcases */
|
|
|
|
|
int maxCycles = Arrays.stream(testcase).max().getAsInt();
|
2017-04-05 18:42:35 -05:00
|
|
|
int [] cache = new int[maxCycles + 1]; // cache is crucial to increase runtime
|
2017-03-10 01:10:37 -06:00
|
|
|
cache[0] = 1;
|
|
|
|
|
for (int i = 1; i <= maxCycles; i++) {
|
|
|
|
|
if (i % 2 == 1) {
|
|
|
|
|
cache[i] = cache[i-1] * 2;
|
|
|
|
|
} else {
|
|
|
|
|
cache[i] = cache[i-1] + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print answers */
|
|
|
|
|
for (int i = 0; i < T; i++) {
|
|
|
|
|
System.out.println(cache[testcase[i]]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|