链接: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. U3D层的运用

    在操作 LayerMask 时常令一些初学者摸不着头脑下面简单说一下层的开关方法:1.首先引入'|'.'&'.'~'的概念与(交集):10000001 & 10000100 == 10 ...

  2. fetch格式

    fetch('url'+参数a, { method: "GET", body: json } .then(res => response.json()) .then(cons ...

  3. 洛谷——P2196 挖地雷

    题目背景 NOIp1996提高组第三题 题目描述 在一个地图上有N个地窖(N<=20),每个地窖中埋有一定数量的地雷.同时,给出地窖之间的连接路径.当地窖及其连接的数据给出之后,某人可以从任一处 ...

  4. 简单的makefile模板

    makefile不是总用到,每次用到的时候总要重新找资料,有点麻烦(怪自己基础知识不扎实,汗).留一个通用模板放这,方便以后使用 CC = gcc CXX = g++ LINK = g++ CFLAG ...

  5. 东方14模拟赛之noip2015/day1/3/神奇的幻方

    总时间限制:  10000ms 单个测试点时间限制:  1000ms 内存限制:  128000kB 描述 幻方是一种很神奇的N*N 矩阵:它由数字 1,2,3, … …,N*N 构成,且每行.每列及 ...

  6. 提高在Xcode上的工作效率

    对于在Xcode上提高工作效率,内功在这不提,对于外力,我将它分为三类: 工具.快捷键和小技巧.主要获得的路径是通过平时积累和看 WWDC12 上的 Session 402:Working Effic ...

  7. Go -- 接口赋值

    在go语言中,接口赋值分为2中情况: 1.将对象实例赋值给接口: 2.将一个接口赋值给另一个接口. 1.将对象实例赋值给接口: 要求对象实现了接口的所有方法. 2.将接口赋值给另一个接口: 假设接口A ...

  8. Go -- socket read的内容以16进制输出

    buf := make([]) reqLen, err := conn.Read(buf) // 遍历, 转为16进制 buffer := new(bytes.Buffer) for _, b := ...

  9. Android自己定义组件系列【6】——进阶实践(3)

    上一篇<Android自己定义组件系列[5]--进阶实践(2)>继续对任老师的<可下拉的PinnedHeaderExpandableListView的实现>进行了分析,这一篇计 ...

  10. Don't Panic! KRACK 没你想象的那么糟

    上海交通大学密码与计算机安全实验室(LoCCS)软件安全小组(GoSSIP)版权所有,转载请与作者取得联系! 著名的计算机学术安全会议CCS在2017年录用了一篇名为Key Reinstallatio ...