408866: GYM103366 F Four Column Hanoi Tower

Memory Limit:256 MB Time Limit:5 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Four Column Hanoi Towertime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Based on the classical problem of tower of Hanoi, there are four rods indexed by A,B,C,D (the only difference between this problem and the classical one) and $$$N$$$ disks of various diameters, which can slide onto any rod. The puzzle begins with disks stacked on one rod in order of decreasing size, the smallest on the top, thus approximating a conical shape. The objective of the puzzle is to move the entire stack to the last rod (indexed by D), obeying the following rules:

  • Only one disk may be moved at a time.
  • Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack or on an empty rod.
  • No disk may be placed on top of a disk that is smaller than it.

You need to calculate the minimum number of moves required to solve the problem.

Input

The first line is a positive integer $$$T(1 \leq T \leq 10000)$$$, indicating that there are $$$T$$$ test data. Next, there are $$$T$$$ lines. Each line has a positive integer $$$N (1 \le N \le 10000)$$$ , indicating the number of plates in each of a test data.

Output

Each test data outputs a line as a positive integer, that is, the minimum number of steps required to move all $$$N$$$ plates from the first column A to the last column D.

ExampleInput
5
1
2
3
4
5
Output
1
3
5
9
13

加入题单

上一题 下一题 算法标签: