POJ topic 1286 Necklace of Beads (Polya theorem)
Necklace of Beads
Time Limit:1000 MS |
|
Memory Limit:10000 K |
Total Submissions:7061 |
|
Accepted:2942 |
Description
Beads of red, blue or green colors are connected together into a circular neckcycle of n beads (n <24 ). if the repetitions that are produced by rotation around the center of the circular neckcycle or reflection to the axis of each ry are all neglected, how many different forms of the neckcycle 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 shoshould contain the output data: Number of different forms, in each line correspondent to the input data.
Sample Input
45-1
Sample Output
2139
Source
Si'an 2002
Question:
N Pearl strings form a circle and are colored in three colors. How many different coloring methods are available.
Different coloring methods are defined as: If this coloring condition is flipped, rotation is different if it is not the same as other conditions.
Solution:
Polya theorem template question.
For the rotation with clockwise length I, it is pow (3 ,__ gcd (n, I );
For flip, if it is an odd number, there are: n * pow (3.0, n/2 + 1 );
For an even number, n/2 * pow (3.0, n/2) + n/2 * pow (3.0, n/2 + 1 );
There are a total of 2 * n cases, and the last is divided by 2 * n
Ac code
#include
#include
#include
int gcd(int a,int b){if(a