Necklace of Beads
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 9.765625 M,其他语言19.53125 M
64bit IO Format: %lld

题目描述

Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n < 24 ). If the repetitions that are produced by rotation around the center of the circular necklace or reflection to the axis of symmetry are all neglected, how many different forms of the necklace are there?

输入描述:

The input has several lines, and each line contains the input data n.
-1 denotes the end of the input file.

输出描述:

The output should contain the output data: Number of different forms, in each line correspondent to the input data.
示例1

输入

复制
4
5
-1

输出

复制
21
39