## poj 1286 polya定理

#### Description

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?

#### Input

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

#### Output

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

4
5
-1

21
39

#### Solution

polya定理模板题

$$\overline{G}$$是n个对象的一个置换群, 用m种颜色染图这n个对象，则不同的染色方案数为：
$L=\frac{1}{|\overline{G}|}[m^{c(\overline{p_1}})+m^{c(\overline{p_2}})+...+m^{c(\overline{p_g}})]$