A stack of n graduated disks sits on the first of three spires, largest at the bottom. To relocate the whole stack to another spire you may move one disk at a time onto a spire, and you may never place a larger disk on top of a smaller one. It is a classic fact that relocating the top k disks reduces to relocating the top k-1 disks, moving the largest, then relocating the k-1 disks again.
Print the exact minimum number of single-disk moves required to relocate the entire tower of n disks. The answer can be large, so print the full exact integer (not modulo anything).
A single line with one integer n, the number of disks.
A single integer: the minimum number of moves.
Example 1
Input
3
Expected
7
Explanation
Three disks need 2 to the 3rd power minus 1 = 7 moves.
Example 2
Input
1
Expected
1
Explanation
A single disk is moved directly in 1 move.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →