Problem E. Necklace of Beads

时间限制 1000 ms   内存限制 32 MB

Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n < 40 ). 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.
 

样例输入

复制
4
5
-1

样例输出

复制
21
39

提交

请先 登录

© 2025 FAQs Contact About