Burnside定理。

可以用Euler函数优化。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define LL __int64 using namespace std; LL Power(int a,int b){
LL ret=1; LL p=(LL)a;
while(b){
if(b&1) ret=ret*p;
p=p*p;
b>>=1;
}
return ret;
} LL Euler(int s){
LL ret=(LL)s;
int l=(int)sqrt(s*1.0);
for(int i=2;i<=l;i++){
if(s%i==0){
ret=ret-ret/(LL)i;
while(s%i==0)
s/=i;
}
}
if(s>1)
ret=ret-ret/s;
return ret;
} LL Burnside(int n){
LL res=0;
for(int i=1;i<=n;i++){
if(n%i==0)
res=res+Power(3,i)*Euler(n/i);
}
if(n&1){
res=res+n*Power(3,n/2+1);
}
else{
res=res+n/2*Power(3,n/2)+n/2*Power(3,n/2+1);
}
return res;
} int main(){
int n;
while(scanf("%d",&n)!=EOF){
if(n==-1) break;
if(n==0) printf("0\n");
else{
LL ans=Burnside(n);
ans=ans/2/n;
printf("%I64d\n",ans);
}
}
return 0;
}

  

POJ 1286的更多相关文章

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

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

  2. poj 1286 Necklace of Beads poj 2409 Let it Bead HDU 3923 Invoker <组合数学>

    链接:http://poj.org/problem?id=1286 http://poj.org/problem?id=2409 #include <cstdio> #include &l ...

  3. 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. ...

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

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

  5. poj 1286&&poj2409 Polya计数 颜色匹配

    #include <iostream> #include <math.h> using namespace std; #define LL long long LL gcd(L ...

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

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

  7. POJ 1286 【POLYA】

    题意: 给你三种颜色的珠子,每次给你N,问在旋转,翻转之后视作相同的情况下,能组成多少种不同的项链. 思路: 让我们借这道题拯救一下我对POLYA定理的理解... sigma(m^(gcd(i,n)) ...

  8. poj 1286 Necklace of Beads

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

  9. POJ 1286 Necklace of Beads(Polya定理)

    点我看题目 题意 :给你3个颜色的n个珠子,能组成多少不同形式的项链. 思路 :这个题分类就是polya定理,这个定理看起来真的是很麻烦啊T_T.......看了有个人写的不错: Polya定理: ( ...

  10. POJ 1286 Necklaces of Beads (Burnside定理,有限制型)

    题目链接:http://vjudge.net/problem/viewProblem.action?id=11117 就是利用每种等价情形算出置换节之后算组合数 #include <stdio. ...

随机推荐

  1. CAD教程----圆的优化命令viewres

    CAD软件为了节省内存加快打开图纸的速度,会在显示圆形的时候,用很粗燥的直线表示园,这时我们可以不节省内存,使用viewres将圆形完整的显示出来. 这个值设置的越大,圆越圆(好绕口!)

  2. F - Truck History

    F - Truck History #include<cstdio> #include<cstring> #include<iostream> #include&l ...

  3. ubuntu中写一个shell脚本的过程

    gedit hello.sh ,然后输入 #!/bin/bash echo "Hello world!" chmod +x hello.sh ./hello.sh

  4. android setCookie 免登录

    CookieSyncManager.createInstance(getActivity()); CookieManager cookieManager = CookieManager.getInst ...

  5. 16进制颜色字符串转为UIColor

    //16进制颜色(html颜色值)字符串转为UIColor +(UIColor *) hexStringToColor: (NSString *) stringToConvert {      NSS ...

  6. CSDN的技术问题

    说CSDN是国内最大最好的技术论坛.预计不会有人反对,可是...CSDN的人,如管理员懂技术吗? 假设您长期在CSDN混.您就会发现他们相当懂得......强奸技术!

  7. 51NOD 1686 第K大区间 二分

    第k大区间   定义一个区间的值为其众数出现的次数.现给出n个数,求将所有区间的值排序后,第K大的值为多少. Input   第一行两个数n和k(1<=n<=100000,k<=n* ...

  8. 0x31 质数

    poj2689 算根号R的质数,然后把L~R区间(这个很小啊)的合数判下 #include<cstdio> #include<iostream> #include<cst ...

  9. hdoj--1248--寒冰王座(完全背包)

    寒冰王座 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  10. IPv6系列-入门指南

    本文是<IPv6系列>文章的第一篇<入门指南>,用于快速了解并上手IPv6. 小慢哥的原创文章,欢迎转载 目录 ▪ 一. 为什么要了解IPv6 ▪ 二. 顾虑:IPv6地址太复 ...