Let it bead ' let it Bead ' Company was located upstairs at the Cannery Row in Monterey, CA. As can deduce from the company name, their business is beads. Their PR department found out that customers is interested in buying colored bracelets. However, over-percent of the target audience insists that the bracelets is unique. (Just Imagine what happened if-women showed up on the same party wearing identical bracelets!) It's a good thing that bracelets can has different lengths and need not being made of beads of one color. Help the boss estimating maximum profit by calculating how many different bracelets can be produced.
A bracelet is a ring-like sequence of s beads each of the which can have one of the C distinct colors. The ring is closed, i.e. have no beginning or end, and has no direction. Assume an unlimited supply of beads of each color. For different values of S and C, calculate the number of different bracelets that can be made.
Input
Every line of the input file defines a test case and contains-integers:the number of available colors C followed by t He length of the bracelets s. Input is terminated by c=s=0. Otherwise, both is positive, and, due to technical difficulties in the Bracelet-fabrication-machine, cs<=32, i.e. thei R product does not exceed 32.
Output
For each test, the output on a, the number of the unique bracelets. The figure below shows the 8 different bracelets The can is made with 2 colors and 5 beads.
Sample Input
1 12 12 25 12 52 66 20 0
Sample Output
123581321
To consider rotation and rollover.
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <iostream>5#include <algorithm>6#include <cmath>7 using namespacestd;8 #defineMAXN 609 #defineLL Long LongTen OneLL pw[ the]; A - intgcdintAintb) - { the if(b==0)returnA; - returnGCD (b,a%b); - } - + intMain () - { + intn,t; A while(1) at { -scanf"%d%d",&t,&n); - if(n==0&&t==0) Break; -pw[0]=1; - for(intI=1; i<=n;i++) pw[i]=pw[i-1]*T; -LL a=0; in for(intI=0; i<n;i++) a+=PW[GCD (i,n)]; -LL b=0; to if(n%2==1) b=n*pw[(n+1)/2]; + Elseb=n/2* (pw[n/2+1]+pw[n/2]); -printf"%lld\n", (A+B)/2/n); the } * return 0; $}
View Code
2017-01-13 11:43:09
"POJ 2409" Let It Bead (permutation, Burnside lemma)