POJ topic 1286 Necklace of Beads (Polya theorem)

Source: Internet
Author: User

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
    
     

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.