Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5870 | Accepted: 3936 |
Description
"Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. As you can deduce from the company name, their business is beads. Their PR department found out that customers are interested in buying colored bracelets. However, over 90 percent of the target audience insists that the bracelets be unique. (Just imagine what happened if two women showed up at the same party wearing identical bracelets!) It's a good thing that bracelets can have different lengths and need not be 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 which can have one of c distinct colors. The ring is closed, i.e. has 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.
A bracelet is a ring-like sequence of s beads each of which can have one of c distinct colors. The ring is closed, i.e. has 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 two integers: the number of available colors c followed by the length of the bracelets s. Input is terminated by c=s=0. Otherwise, both are positive, and, due to technical difficulties in the bracelet-fabrication-machine, cs<=32, i.e. their product does not exceed 32.
Output
![](https://i-blog.csdnimg.cn/blog_migrate/d7fedfc9cfc7b0452c2168c09b64f88e.jpeg)
Sample Input
1 1 2 1 2 2 5 1 2 5 2 6 6 2 0 0
Sample Output
1 2 3 5 8 13 21
Source
数学问题 统计 polya计数原理
直接套用polya原理。
旋转同构的话,算出每次旋转i个的循环数$gcd(n,i)$
翻转同构的话,考虑奇偶性:奇数$(n+1)/2$ ,偶数 $ n/2 + (n/2+1)$ (边上的对称轴、顶点的对称轴有区别)
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<cstring> 5 #define LL long long 6 using namespace std; 7 const int mxn=1010; 8 int read(){ 9 int x=0,f=1;char ch=getchar(); 10 while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();} 11 while(ch>='0' && ch<='9'){x=x*10-'0'+ch;ch=getchar();} 12 return x*f; 13 } 14 int n,m; 15 LL ksm(LL a,int k){ 16 LL res=1; 17 while(k){ 18 if(k&1)res=res*a; 19 a=a*a; 20 k>>=1; 21 } 22 return res; 23 } 24 int gcd(int a,int b){return (!b)?a:gcd(b,a%b);} 25 int main(){ 26 int i,j; 27 LL ans; 28 while(1){ 29 m=read();n=read(); 30 if(!n && !m)break; 31 ans=0; 32 for(i=1;i<=n;i++) 33 ans+=ksm(m,gcd(n,i)); 34 if(n&1) ans+=ksm(m,n/2+1)*n; 35 else ans+=ksm(m,n/2)*n/2+ksm(m,n/2+1)*n/2; 36 ans/=2*n; 37 printf("%lld\n",ans); 38 } 39 return 0; 40 }