1116: Let it Bead 

Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByte
Total Submit: 7            Accepted:4

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.

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

For each test case output on a single line the number of unique bracelets. The figure below shows the 8 different bracelets that can be made with 2 colors and 5 beads.

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

经典题目

#include<stdio.h>
#include<string.h>
int eular(int n)
{
int ret=,i;
for(i=; i*i<=n; i++)
{
if(n%i==)
{
ret*=i-;
n/=i;
while(n%i==)
{
n=n/i;
ret*=i;
}
}
if(n==)
break;
}
if(n>)
ret*=n-;
return ret;
}
int po(int a,int b)
{
int ret=,i;
for(i=; i<=b; i++)
ret*=a;
return ret;
}
int main()
{
int n,ans,i,m;
while(~scanf("%d%d",&m,&n))
{
if(!n&&!m)break;
ans=;
for(i=; i*i<n; i++)
{
if(n%i==)
{
ans+=eular(n/i)*po(m,i);
ans+=eular(i)*po(m,n/i);
}
}
if(i*i==n)
ans+=eular(n/i)*po(m,i);
if(n&)
ans+=po(m,n/+)*n;
else
ans+=po(m,n/)*n/+po(m,n/+)*n/;
printf("%d\n",ans/n/);
}
return ;
}

也是很优秀的写法

#include<bits/stdc++.h>
using namespace std;
int c,n,ans;
int po(int p,int n)
{
int ans=;
while(n)
{
if(n&)ans*=p;
p*=p,n>>=;
}
return ans;
} int main()
{
while(cin>>c>>n&&(c||n))
{
ans=;
for(int i=; i<=n; i++)
ans+=po(c,__gcd(n,i));
if(n&)
ans+=n*po(c,n/+);
else
ans+=(po(c,n/+)+po(c,n/))*(n/);
cout<<ans//n<<endl;
}
return ;
}

组合数学之Polya计数 TOJ1116 Let it Bead的更多相关文章

  1. 《程序设计中的组合数学》——polya计数

    我们在高中的组合数学中常常会碰到有关涂色的问题,例如:用红蓝两种颜色给正方形的四个顶点涂色,会有几种不同的方案.在当时,我们下意识的认为,正方形的四个顶点是各不相同的,即正方形是固定的.而实际上我们知 ...

  2. 组合数学及其应用——polya计数

    在处理类似下面的问题中,一般的计数方法会出现问题:假如你要用红.蓝两种颜色给一个正四面体的四个顶点着色,试问存在多少种不同的着色方案? 在高中我们常用的方法是模拟涂色过程,分情况讨论,然后基于分步乘法 ...

  3. hdu 2865 Polya计数+(矩阵 or 找规律 求C)

    Birthday Toy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  4. Polya计数

    Let it Bead Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5365   Accepted: 3585 Descr ...

  5. hdu 5868:Different Circle Permutation 【Polya计数】

    似乎是比较基础的一道用到polya定理的题,为了这道题扣了半天组合数学和数论. 等价的题意:可以当成是给正n边形的顶点染色,旋转同构,两种颜色,假设是红蓝,相邻顶点不能同时为蓝. 大概思路:在不考虑旋 ...

  6. hdu 5868 Polya计数

    Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K ...

  7. HDU 4633 Who's Aunt Zhang (2013多校4 1002 polya计数)

    Who's Aunt Zhang Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. 群论&Polya计数

    群论&Polya计数 其实在我听课的过程中,我发现针对于学习OI中的群并没有什么过多必要向内学习... 群 以后会补的. 就是\(QQ\)群. 置换 置换就是一个... \[ \begin{m ...

  9. 组合数学之Pólya计数理论

    1 群 群$(G, cdot)$: 闭合, 结合律, 幺元, 逆 1.1 置换群 置换为双射$pi:[n]to [n]$, 置换之间的操作符 $cdot$ 定义为函数的复合, 即$(pi cdot s ...

随机推荐

  1. 火狐浏览器不支持location.reload()(以改变页面大小时重新刷新页面为例)

    背景:当页面大小改变时需要重新刷新页面,以适应相应的尺寸 解决方法: var url = window.location.href; var parm = parseInt(Math.random() ...

  2. JDBC + SAP云平台 = 运行在云端的数据库应用

    在前一篇文章JPA + EclipseLink + SAP云平台 = 运行在云端的数据库应用我介绍了如何通过JPA和EclipseLink操作部署在SAP云平台上的HANA数据库实例. 在这篇文章里, ...

  3. 读书笔记2013-2 Linux内核设计与实现A

    读书笔记2013-2 Linux内核设计与实现A <Linux内核设计与实现> 简介 这本书不是想Linux源码剖析那样一行行分析Linux源代码的书,而是从Linux历史,Linux哲学 ...

  4. Unity中的各种寻找GameObject方法归纳

    1.GameObject.Find():寻找Hierarchy面板中的activie 不为false的游戏对象: 路径如官方事例写法: public class ExampleClass : Mono ...

  5. codeforce Gym 100500I Hall of Fame (水)

    题意:统计一些串中,字母的出现频率,不分大小写,找出现频率最高5个字符(相同频率优先取字典序大的),把他们的对应的值加起来判断以下是否大于62. 没出现的不算. #include<cstdio& ...

  6. JS实现全排列

    https://www.jb51.net/article/39291.htm JavaScript全排列的六种算法 具体实现 算法一:交换(递归) 复制代码代码如下: <html xmlns=& ...

  7. 使用ErrorProvider组件验证文本框输入

    实现效果: 知识运用: ErrorProvider组件的BlinkStyle属性 //指示错误图标的闪烁时间 public ErrorBlinkStyle BlinkStyle{ get;set; } ...

  8. shell的切换

    从zsh切换到bash:在命令行输入bash即可 从bash切换到zsh:在命令行输入zsh即可

  9. Python——函数入门(二)

    一.函数的参数 我们在定义函数时,可以定义形式参数(简称形参),这些形参的值在函数调用的时候才会确定,形参的值由调用者负责传入. 1.关键字参数 在Python中,函数的参数名并不是没有意义的,在调用 ...

  10. 在Python中使用help帮助

    在Python中使用help帮助 >>> import numpy >>> help(numpy.argsort) Help on function argsort ...