链接:http://poj.org/problem?id=1286

http://poj.org/problem?id=2409

 #include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
LL P_M( LL a, LL b )
{
LL res=, t=a;
while (b){
if(b&)res*=t;
t*=t;
b>>=;
}
return res;
}
int a[], vi[];
void dfs( int i )
{
if( !vi[i] ){
vi[i]=;
dfs(a[i]);
}
} int find(int t, int n ) // 求循环节 s == gcd( n, t ) ;
{
memset(vi, , sizeof vi);
memset(a, , sizeof a);
for( int i=; i<=n; ++ i ){
int e=(i+t-)%n;
if( e== )e=n;
a[i]=e;
}
int s=;
for( int i=; i<=n; ++ i ){
if(!vi[i]){
dfs(i);
s++;
}
}
return s;
}
int gcd( int x, int y )
{
return y==?x:gcd( y, x%y );
}
int main( )
{
int N;
while( scanf("%d", &N)!= EOF){
if( N==- )break;
if( N== ){puts(""); continue;}
LL ans=;
if( !(N&) ){
ans=P_M(3LL, N);
for( int i=; i<=N; ++i ){
int t=find(i, N);
ans+=P_M( 3LL,t );
}
ans+=(LL)(N/)*(P_M(3LL,(N+)/));
ans+=(LL)(N/)*P_M(3LL,N/);
}
else{
for( int i=; i<N; ++i ){
ans+=P_M(3LL, gcd(i, N));
}
ans+=(LL)(N)*(P_M(3LL,N/+)); }
printf( "%d\n", ans/(*N) );
}
return ;
}

poj 1286

 #include <cstdio>
#include <iostream>
using namespace std;
int N, M;
typedef long long LL;
LL P_M(int a, int b )
{
LL res=,t=a;
while(b){
if(b&)res*=t;
t*=t;
b>>=;
}
return res;
}
int gcd( int x, int y )
{
return y==?x:gcd( y, x%y );
}
LL polya( int k, int m )
{
LL ans=;
for( int i=; i<m; ++ i ){
ans+=P_M(k, gcd( i, m ));
}
if( m& ){
ans+=(LL)(m*P_M( k, m/+ ) );
}
else {
ans+=(LL)m/*P_M(k, m/);
ans+=(LL)m/*P_M(k, m/+);
}
if(m)ans/=,ans/=m;
return ans;
}
int main( )
{
while(scanf("%d%d", &N,&M)!=EOF, N+M ){
printf("%lld\n", polya(N, M));
}
return ;
}

poj 2409

 #include <cstdio>
#include <iostream>
using namespace std;
typedef long long LL;
const LL M=1e9+;
LL P_M(int a, int b )
{
LL res=,t=a;
while(b){
if(b&)res*=t, res%=M;
t*=t, t%=M;
b>>=;
}
return res;
}
int gcd( int x, int y )
{
return y==?x:gcd( y, x%y );
}
LL polya( int k, int m )
{
LL ans=;
for( int i=; i<m; ++ i ){
ans+=P_M(k, gcd( i, m ));
ans%=M;
}
if( m& ){
ans+=(LL)(m*P_M( k, m/+ ) );
}
else {
ans+=(LL)m/*P_M(k, m/);
ans+=(LL)m/*P_M(k, m/+);
}
ans%=M;
return (ans*P_M(*m,M-))%M;// 求逆元
}
int main( )
{
int T, N, K, t=;
scanf("%d", &T);
while(T--){
scanf("%d%d", &N,&K);
printf("Case #%d: %I64d\n", t++, polya(N, K));
}
return ;
}

hdu 3923

poj 1286 Necklace of Beads poj 2409 Let it Bead HDU 3923 Invoker <组合数学>的更多相关文章

  1. poj 1286 Necklace of Beads &amp; poj 2409 Let it Bead(初涉polya定理)

    http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...

  2. 数学计数原理(Pólya):POJ 1286 Necklace of Beads

    Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7763   Accepted: 3247 ...

  3. POJ 1286 Necklace of Beads(项链的珠子)

    Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7874   Accepted: 3290 ...

  4. POJ 1286 Necklace of Beads(Polya简单应用)

    Necklace of Beads 大意:3种颜色的珠子,n个串在一起,旋转变换跟反转变换假设同样就算是同一种,问会有多少种不同的组合. 思路:正规学Polya的第一道题,在楠神的带领下,理解的还算挺 ...

  5. poj 2409 Let it Bead && poj 1286 Necklace of Beads(Polya定理)

    题目:http://poj.org/problem?id=2409 题意:用k种不同的颜色给长度为n的项链染色 网上大神的题解: 1.旋转置换:一个有n个旋转置换,依次为旋转0,1,2,```n-1. ...

  6. poj 1286 Necklace of Beads【polya定理+burnside引理】

    和poj 2409差不多,就是k变成3了,详见 还有不一样的地方是记得特判n==0的情况不然会RE #include<iostream> #include<cstdio> us ...

  7. POJ 1286 Necklace of Beads(Polya原理)

    Description Beads of red, blue or green colors are connected together into a circular necklace of n ...

  8. poj 1286 Necklace of Beads (polya(旋转+翻转)+模板)

      Description Beads of red, blue or green colors are connected together into a circular necklace of ...

  9. poj 1286 Necklace of Beads

    这是做的第一道群论题,自然要很水又很裸.注意用long long. 就是用到了两个定理 burnside :不等价方案数=每个置换的不动置换方案数的和 / 置换个数 polya: 一个置换的不动置换方 ...

随机推荐

  1. app_data中的数据库使用

    原文发布时间为:2008-07-24 -- 来源于本人的百度文章 [由搬家工具导入] ASP.NET中利用VWD操作数据库 建立本地数据库   你可以轻易地在Visual Studio的Web应用程序 ...

  2. Intent显示启动与隐式启动

    Android的Acitivity启动大致有两种方式:显式启动与隐式启动.下面分别介绍: 1.显示启动: 清单文件注册Activity <activity android:name=" ...

  3. class文件检查器

    Class文件检查器保证装载的class文件内容有正确的内部结构,并且这些class文件互相间协调一致.Class文件检查器实现的安全目标之一就是程序的健壮性.如果某个有漏洞的编译器,或某个聪明的黑客 ...

  4. JVM指令详解(下)

    九.自增减指令 该指令用于对本地(局部)变量进行自增减操作.该指令第一参数为本地变量的编号,第二个参数为自增减的数量. 比如对于代码:                 int d=10; d++; d ...

  5. Linux 设备驱动的固件加载【转】

    转自:http://blog.csdn.net/zqixiao_09/article/details/51106663 版权声明:本文为博主原创文章,未经博主允许不得转载. 作为一个驱动作者, 你可能 ...

  6. 11深入理解C指针之---指针和常量

    该系列文章源于<深入理解C指针>的阅读与理解,由于本人的见识和知识的欠缺可能有误,还望大家批评指教. 指针作为C语言的左膀右臂,使用方便,修改容易,引用数据快速都是很有前景的应用.C语言中 ...

  7. 记录vim经常使用的几个命令

    vi/vim 基本使用方法 vi编辑器是所有Unix及Linux系统下标准的编辑器. $ vim 1.txt 以vi打开一个文件就直接进入一般模式了(这是默认的模式).在这个模式中, 你可以使用上下左 ...

  8. 安装phpssdb扩展:

    安装 igbinary   扩展(安装phpssdb扩展时候要用到--enable-ssdb-igbinary): clone  https://github.com/igbinary/igbinar ...

  9. cin和scanf的速度差别

    好长时间没有遇到这种问题了,以前虽然知道scanf比cin快,但是没想到快这么多,见图. 50万的数据. scanf输入: cin输入: 网上说用std::ios::sync_with_stdio(f ...

  10. (4)Unity3d镜头

    Input.GetMouseButton()://获取鼠标按钮状态,0-鼠标左键,1-鼠标右键,2-鼠标中键: Input.GetAxis("Mouse X ") //鼠标水平向移 ...