"POJ 2409" Let It Bead (Polya)

Source: Internet
Author: User

"POJ 2409" Let It Bead (Polya)

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 5378 Accepted: 3596

Description

"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

Source

ULM Local 2000


Bare Polya. , after the rotation of symmetry after the same kind of calculation.

This formula is set on ....


#include <iostream> #include <cmath> #include <vector> #include <cstdlib> #include <cstdio > #include <cstring> #include <queue> #include <stack> #include <list> #include <algorithm > #include <map> #include <set> #define LL long long#define Pr pair<int,int> #define FREAD () freopen (" In.in "," R ", stdin) #define FWRITE () freopen (" Out.out "," w ", stdout) using namespace std;const int INF = 0x3f3f3f3f;const int MSZ = 10000;const int mod = 1e9+7;const double eps = 1e-8;int main () {//fread ();//fwrite (); int C,s;int ans;while (~scanf ("%d %d ", &c,&s) && (c+s)) {ans = 0;for (int i = 1; I <= s; ++i) ans + = (int) pow (1.0*C,__GCD (i,s)); if (s&1) p rintf ("%d\n", (ans+ (int) Pow (1.0*c, (s+1)/2) *s)/(2*s)), Else printf ("%d\n", (ans+ (int) POW (1.0*C,S/2) * (S/2) + (int) POW ( 1.0*c, (s-2)/2+2) * (S/2))/(2*s));} return 0;}





"POJ 2409" Let It Bead (Polya)

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.