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

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
/*
poj 2409 Polya模板题 旋转:
L = sum(k^Ci)/n(i = 0,1.....n-1) 求出每次旋转i位的和
顺时针旋转i格的置换中,循环的个数为GCD(n,i),长度为n/GCD(n,i).
so Ci = GCD(n,i) 翻转:
当n为偶数时,n/2个的置换Ci = n/2; n/2个的置换Ci = n/2-1
当n为奇数时,n个置换Ci = n/2+1 hhh-2016-04-19 10:06:23
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <math.h>
using namespace std;
#define lson (i<<1)
#define rson ((i<<1)|1)
typedef long long ll;
const int maxn = 100040; ll gcd(ll a, ll b) {
return b ? gcd(b, a%b) : a;
}
ll pow(ll a, ll b)
{
ll res = 1;
while(b)
{
if(b&1) res *= a;
a = a*a;
b >>= 1;
}
return res;
} ll polya(ll n,ll k)
{
ll ans = 0;
for(int i = 1; i <= n; i++)
{
ans += pow(k,gcd(n,i));
} if(n & 1)
ans += pow(k,n/2+1)*n;
else
{
ans += pow(k,n/2)*(n/2);
ans += pow(k,n/2+1)*(n/2);
}
return ans/(n*2);
} int main()
{
ll n,c;
while(scanf("%I64d%I64d",&c,&n) != EOF)
{
if(!n && !c)
break;
printf("%I64d\n",polya(n,c));
}
return 0;
}

  

Necklace of Beads
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 7525   Accepted: 3132

Description

Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n < 24 ). If the repetitions that are produced by rotation around the center of the circular necklace or reflection to the axis of symmetry are all neglected, how many different forms of the necklace are there? 

Input

The input has several lines, and each line contains the input data n. 
-1 denotes the end of the input file. 

Output

The output should contain the output data: Number of different forms, in each line correspondent to the input data.

Sample Input

4
5
-1

Sample Output

21
39
/*
poj 1286 polya(euler优化) 依旧是模板题,只是在上面加了优化
优化:(黑书)
以前都是直接枚举i来求解。 但是可以考虑通过枚举循环节的长度L,然后计算有多少个i
L = n/(GCD(n,i)) -> GCD(n,i) = n/L
不妨设 a = n/L = GCD(n,i) , 不妨设 i = a*t -> GCD(n,i) = GCD(a*L,a*t) = a
所以只有 GCD(L,t) = 1是才行。 0 ≤ i <n ---> 0 ≤ t < L(n/a)
即小于L且与L互质的个数,这个用欧拉函数解决 hhh-2016-04-19 11:14:49
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <math.h>
using namespace std;
#define lson (i<<1)
#define rson ((i<<1)|1)
typedef long long ll;
const int maxn = 100040; ll euler(ll n)
{
ll ans = n;
for(int i = 2;i*i <= n;i++)
{
if(n % i == 0)
{
ans -= ans/i;
while(n % i == 0)
{
n /= i;
}
}
}
if(n > 1) ans -= ans/n;
return ans;
} ll gcd(ll a, ll b) {
return b ? gcd(b, a%b) : a;
}
ll Pow(ll a, ll b)
{
ll res = 1;
while(b)
{
if(b&1) res *= a;
a = a*a;
b >>= 1;
}
return res;
} ll polya(ll n,ll k)
{
ll ans = 0;
for(ll i = 1; i <= n; i++)
{
if(n % i == 0) //枚举循环节的长度
ans += Pow(k,i)*euler(n/i);
} if(n & 1)
ans += Pow(k,n/2+1)*n;
else
{
ans += Pow(k,n/2)*(n/2);
ans += Pow(k,n/2+1)*(n/2);
}
return ans/(n*2);
} int main()
{
ll n;
while(scanf("%I64d",&n) != EOF)
{
if(n == -1)
break;
if(n == 0)
printf("0\n");
else
printf("%I64d\n",polya(n,3));
}
return 0;
}

  

Invoker

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 122768/62768 K (Java/Others)
Total Submission(s): 1426    Accepted Submission(s): 610

Problem Description
On of Vance's favourite hero is Invoker, Kael. As many people knows Kael can control the elements and combine them to invoke a powerful skill. Vance like Kael very much so he changes the map to make Kael more powerful.

In his new map, Kael can control n kind of elements and he can put m elements equal-spacedly on a magic ring and combine them to invoke a new skill. But if a arrangement can change into another by rotate the magic ring or reverse the ring along the axis, they will invoke the same skill. Now give you n and m how many different skill can Kael invoke? As the number maybe too large, just output the answer mod 1000000007.

 
Input
The first line contains a single positive integer T( T <= 500 ), indicates the number of test cases.
For each test case: give you two positive integers n and m. ( 1 <= n, m <= 10000 )
 
Output
For each test case: output the case number as shown and then output the answer mod 1000000007 in a line. Look sample for more information.
 
Sample Input
2
3 4
1 2
 
Sample Output
Case #1: 21 Case #2: 1
/*
HDU 3923 Ploya定理+逆元 裸Polya计数,只是在后面求个逆元即可 hhh-2016-04-19 11:40:12
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <math.h>
using namespace std;
#define lson (i<<1)
#define rson ((i<<1)|1)
typedef long long ll;
const int maxn = 100040;
const int mod = 1000000007;
ll euler(ll n)
{
ll ans = n;
for(int i = 2;i*i <= n;i++)
{
if(n % i == 0)
{
ans -= ans/i;
while(n % i == 0)
{
n /= i;
}
}
}
if(n > 1) ans -= ans/n;
return ans%mod;
} ll Pow(ll a, ll b)
{
ll res = 1;
a %= mod;
while(b)
{
if(b&1) res =res*a%mod;
a = a*a%mod;
b >>= 1;
}
return res%mod;
} ll polya(ll n,ll k)
{
ll ans = 0;
for(ll i = 1; i <= n; i++)
{
if(n % i == 0) //枚举循环节的长度
ans =(ans+Pow(k,i)*euler(n/i)%mod)%mod;
} if(n & 1)
ans =(ans+Pow(k,n/2+1)*n%mod)%mod;
else
{
ans = (ans+Pow(k,n/2)*(n/2)%mod)%mod;
ans = (ans+Pow(k,n/2+1)*(n/2)%mod)%mod;
}
ll t = Pow(n*2,mod-2); //求逆元
return ans*t%mod;
} int main()
{
ll n,c;
int T,cas = 1;
scanf("%d",&T);
while(T--)
{
scanf("%I64d%I64d",&c,&n);
printf("Case #%d: ",cas++);
printf("%I64d\n",polya(n,c));
}
return 0;
}

DIY Cube

Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 637    Accepted Submission(s): 313

Problem Description
Mr. D is interesting in combinatorial enumeration. Now he want to find out the number of ways on painting the vertexes of a cube. Suppose there are C different colors and two paintings are considered the same if they can transform from one to another by rotation.
 
Input
There are multiple test cases in the input, the first line of input contains an integer denoting the number of test cases.
For each test case, there are only one integer C, denoting the number of colors. (1 <= C <= 1000000000)
 
Output
For each test case, output the the number of painting ways. And if the number is equal or larger than 1015, output the last 15 digits.
 
Sample Input
3
1
2
112
 
Sample Output
Case 1: 1
Case 2: 23
Case 3: 031651434916928
//hdu 3547 用C种颜色对正方形的八个顶点染色
//如果用1234表示顶面 5678表示底面
//1.绕着相互对立的两个面旋转,有90度,180度,270度,所以总共有3*3=9种情况。
// 绕90 or 270. {1 2 3 4} {5,6,7,8} 2个循环节 总共有6中情况
// 绕180 {1,3}{2,4}{5,7}{6,8} 4个循环节 共有3种情况
//2.绕着相互对立的两个边旋转,有180度这样,所以总共有6*1=6种。
// {1,7}{2,8}{3,4}{5,6} 4个循环节
//3.绕着对角点旋转,有120度,240度这样,所以总共有4*2=8种。
// {2,5,7}{1,3,8}{6}{4} 4个循环节
//4.不动,有一种。 {1}{2}{3}{4}{5}{6}{7}{8} 8个循环节
//假设有C中颜色 则共有C^8 + 17*C^4 + 6*C^2
import java.math.BigInteger;
import java.util.Scanner; public class Main { public static void main(String[] args) {
// TODO 自动生成的方法存根
Scanner cin = new Scanner(System.in);
int T = cin.nextInt();
int cas = 1;
while(T>0){
BigInteger c = cin.nextBigInteger(); BigInteger t1 = c.pow(8);
BigInteger t2 = c.pow(4);
BigInteger t3 = c.pow(2);
// System.out.println("t1:"+t1);
// System.out.println("t2:"+t2);
// System.out.println("t3:"+t3);
t2 = t2.multiply(BigInteger.valueOf(17));
t3 = t3.multiply(BigInteger.valueOf(6)); BigInteger ans = t1.add(t2).add(t3);
String tans = ans.divide(BigInteger.valueOf(24)).toString();
int len = tans.length();
System.out.print("Case " + cas+": ");
if(len <= 15)
System.out.println(tans);
else
System.out.println(tans.substring(len-15));
cas++;
T--;
}
}
}

  

 

Polya计数的更多相关文章

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

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

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

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

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

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

  4. 群论&Polya计数

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

  5. 薛非《品悟C-抛弃C程序设计中的谬误与恶习》读后感part1【转】

    薛非<品悟C-抛弃C程序设计中的谬误与恶习>读后感part1 作者:宝贝孙秀楠﹣大连程序员 发表于2012年10月5日由admin 出处:http://sunxiunan.com/?p=2 ...

  6. hdu 5868 Polya计数

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

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

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

  8. Netty中ByteBuf的引用计数线程安全的实现原理

    原文链接 Netty中ByteBuf的引用计数线程安全的实现原理 代码仓库地址 ByteBuf 实现了ReferenceCounted 接口,实现了引用计数接口,该接口的retain(int) 方法为 ...

  9. 嵌入式程序设计中C/C++代码的优化

    虽然使软件正确是一个工程合乎逻辑的最后一个步骤,但是在嵌入式的系统开发中,情况并不总是这样的.出于对低价产品的需求,硬件的设计者需要提供刚好足够的存储器和完成工作的处理能力.所以在嵌入式软件设计的最后 ...

随机推荐

  1. python自动发邮件

    from email.header import Header from email.mime.text import MIMEText from email.utils import parsead ...

  2. 【iOS】OC-AFNetworking 2.0 跟踪文件上传进度

    我是较新的 AFNetworking 2.0.使用下面的代码片段,我已经能够成功地将一张照片上传到我的 url.我想要跟踪的增量上载进度,但我找不到这样做 2.0 版的示例.我的应用程序是 iOS 7 ...

  3. PHP处理上传文件

    HTML中使用type = 'file'类型的表单可以向服务器上传文件: 上传文件的表单必须在form中定义enctyp = 'multipart/form-data': HTML代码如下: < ...

  4. SOAPtest报错:error occurred during initialization of vm解决方法

    参考:http://forums.parasoft.com/index.php?act=ST&f=36&t=614 安装SOAPtest报错:error occurred during ...

  5. 表单提交中的input、button、submit的区别

    1.input[type=submit] 我们直接来看例子: 代码如下: <form> <input name="name"> <input type ...

  6. (Sqlyog或Navicat不友好处)SHOW ENGINE INNODB STATUS 结果为空或结果为=====================================

    因为最近在学习innodb引擎,所以就在自己的sqlyog上执行上述命令: SHOW ENGINE INNODB STATUS 结果显示如下: 换了个客户端navicat,执行如下: 最后登录到服务器 ...

  7. Java-Maven(四):Eclipse集成Maven环境配置

    一般maven都需要集成到IDE上使用的,而不是单独的使用,常见的maven可集成IDE:eclipse.IntelliJ IDEA.但这里就只学习eclipse集成maven的基础上,进行maven ...

  8. python常用的一些东西——sys、os等(转)

    1.常用内置函数:(不用import就可以直接使用)      help(obj) 在线帮助, obj可是任何类型     callable(obj) 查看一个obj是不是可以像函数一样调用     ...

  9. Web标准的简单理解 不同内核浏览器的差异以及浏览器渲染简介(转)

    Web标准是一系列标准的集合.这些标准大概分三方面:结构.表现和行为.结构化主要有HTML, XHTML和XML,表现主要有CSS,行为标准主要包括对象模型,如 W3C DOM.ECMAScript等 ...

  10. CentOS 6.8下二级域名及目录的绑定

    二级域名对应目录的绑定: 第一步: 开启mod_rewrite模块,默认是开启的,这里可以查下是否开启 终端输入:vim /etc/httpd/conf/httpd.conf  回车 查看188行:L ...