poj-2409 Let It bead

Source: Internet
Author: User

Test instructions

Give a C color and s beads;

The beads are dyed and worn into a ring;

Rotate and flip the same as isomorphic;

The number of solutions to be obtained;


Exercises

Polya the number of naked questions;

Define m as the number of colors, and C (PI) as the number of cyclic sections of pi for this permutation;

So according to the theorem, the answer is L;

Then just find out the various permutations of the cycle section is good;

Two permutations are allowed in the problem, first consider rotation;

Rotation there are n substitution methods, respectively, is 0, turn 360/n, turn 2*360/n ... Turn (n-1) *360/n;

The number of cycles of each type is actually GCD, and then the sum is brought into the summation form;

Then consider flipping, with odd-even discussions;

Odd can cross each bead to do the axis of symmetry, then the permutation number is n, the link number is n/2+1;

Even can be over two diagonal beads do the axis of symmetry, displacement number is N/2, the number of links is n/2+1 (other beads divided by 2, plus two on the axis);

can also but beads, such displacement number is also N/2, the number of links is N/2;

And then it ended with a 2*n;


Code:


#include <stdio.h> #include <string.h> #include <algorithm> #define N 110000using namespace std; typedef long LONG Ll;int gcd (int a,int b) {int t=a%b;while (t) {a=b,b=t;t=a%b;} return b;} int pow (int x,int y) {int ret=1;while (y) {if (y&1) ret*=x;x*=x;y>>=1;} return ret;} int main () {int n,m,i,j,k;while (scanf ("%d%d", &m,&n) && (n| | m) {for (i=1,k=0;i<=n;i++) K+=pow (M,GCD (n,i)), if (n&1) K+=n*pow (m,n/2+1); Elsek+=n/2*pow (M,N/2) +n/2*pow (m,n/ 2+1); k/=2*n;printf ("%d\n", k);} return 0;}


poj-2409 Let It bead

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.