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. Windows计算机重置TCP / IP

    传输控制协议 (TCP / IP)是Internet上使用的通信协议. 在Windows的早期版本中,TCP / IP是一个单独的可选组件,可以像其他任何协议一样删除或添加. 早期版本中,从Windo ...

  2. Linux之bash shell的学习

    1.什么是bash  shell bash 是Bourne Again Shell的简称,是从unix系统中的sh发展而来,是用户和偶Linux内核交互的工具,用户通过bash操作内核完成系统的使用和 ...

  3. javaSe-hashMap

    package com.java.chap08.sec05; public class Student { private String name; private Integer age; publ ...

  4. EF6.0注意事项

    EF6 1.必须要添加Entitiframework 2.必须要添加必须要添加Entitiframework.Sqlserver 3.单元测试一定要有配置文件里面一定要有连接字符串和初始化配置文件节点 ...

  5. python 搜集参数

    def print_params(*params): print(params) print_params('Testing')print_params(1,2,3) #参数前的星号将所有值放置在同一 ...

  6. django 数据库中中文转化为韩语拼音

    1.安装模块 django-uuslug pip install django-uuslug 2.导入模块 from uuslug import slugify 3.使用模块 slugify('天龙八 ...

  7. Linux centos 6 配置php环境,扩展redis

    1.首先安装一个虚拟机(我自己版本:VM 10.0.4) yum -y install openssl psmisc openssl-devel php-devel pcre-devel gcc gc ...

  8. 使用CAShapeLayer实现复杂的View的遮罩效果

    一.案例演示 最近在整理一个聊天的项目的时候,发送图片的时候,会有一个三角的指向效果,指向这张图片的发送者.服务端返回给我们的图片只是一张矩形的图片,我们如何把一张矩形的图片或者View,加上一层自定 ...

  9. 【离线 线段树分治】bzoj4025: 二分图

    昨天mac的gdb挂了,今天怎么笔记本的gdb也挂了…… Description 神犇有一个n个节点的图.因为神犇是神犇,所以在T时间内一些边会出现后消失.神犇要求出每一时间段内这个图是否是二分图.这 ...

  10. 批量ping IP并检测IP延迟率和丢包率脚本

    脚本文件如下: #!/bin/bash #Author:Mr.Ding #Created Time:2018-08-26 07:23:44 #Name:ping.sh #Description: sh ...