POJ 1286
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的更多相关文章
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...
- 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 ...
- 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. ...
- poj 1286 Necklace of Beads【polya定理+burnside引理】
和poj 2409差不多,就是k变成3了,详见 还有不一样的地方是记得特判n==0的情况不然会RE #include<iostream> #include<cstdio> us ...
- poj 1286&&poj2409 Polya计数 颜色匹配
#include <iostream> #include <math.h> using namespace std; #define LL long long LL gcd(L ...
- POJ 1286 Necklace of Beads(Polya原理)
Description Beads of red, blue or green colors are connected together into a circular necklace of n ...
- POJ 1286 【POLYA】
题意: 给你三种颜色的珠子,每次给你N,问在旋转,翻转之后视作相同的情况下,能组成多少种不同的项链. 思路: 让我们借这道题拯救一下我对POLYA定理的理解... sigma(m^(gcd(i,n)) ...
- poj 1286 Necklace of Beads
这是做的第一道群论题,自然要很水又很裸.注意用long long. 就是用到了两个定理 burnside :不等价方案数=每个置换的不动置换方案数的和 / 置换个数 polya: 一个置换的不动置换方 ...
- POJ 1286 Necklace of Beads(Polya定理)
点我看题目 题意 :给你3个颜色的n个珠子,能组成多少不同形式的项链. 思路 :这个题分类就是polya定理,这个定理看起来真的是很麻烦啊T_T.......看了有个人写的不错: Polya定理: ( ...
- POJ 1286 Necklaces of Beads (Burnside定理,有限制型)
题目链接:http://vjudge.net/problem/viewProblem.action?id=11117 就是利用每种等价情形算出置换节之后算组合数 #include <stdio. ...
随机推荐
- iOS 相似QQ空间表视图下拉头部视图放大效果实现
UITableView 是 UIScrollView 的子类. 所以 UIScrollView 的代理方法.在UITableView 上相同可以得到适用. 既然如此那么我们就行知道.在表格下拉的过程中 ...
- Visual studio 编译时copy文件、文件夹
项目属性--生成事件 添加命令 xcopy /y /d "$(SolutionDir)Dll\Linphone\*.dll" "$(TargetDir)\Linphone ...
- centos 下 KVM虚拟机的创建、管理与迁移
kvm虚拟机管理 一.环境 role hostname ip OS kvm_server target 192.168.32.40 ...
- DB-MySQL:MySQL 事务
ylbtech-DB-MySQL:MySQL 事务 1.返回顶部 1. MySQL 事务 MySQL 事务主要用于处理操作量大,复杂度高的数据.比如说,在人员管理系统中,你删除一个人员,你即需要删除人 ...
- maven的pom.xml配置标签
转自:https://blog.csdn.net/wf787283810/article/details/76188595 <project xmlns="http://maven.a ...
- 在Ubuntu Server下搭建LAMP环境
1 LAMP的安装 LAMP通常是指Linux+Apache+MySQL+PHP组合形成的一套可以运行PHP程序的体系,并不是一个软件的名称.没有安装MySQL的服务器依然可以在其它条件完备的情况下运 ...
- c#常量如何使用
c#中类中定义一个常量,在其他地方使用的时候使用类名.常量
- httpclient定时请求实例
1.pom.xml <properties> <slf4j.version>1.7.21</slf4j.version> <okhttp.version> ...
- 软件测试作业-selenium
一.作业要求 1.安装SeleniumIDE插件. 2.学会使用SeleniumIDE录制脚本和导出脚本. 3.访问网址使用学号登录系统,进入系统后可以看到该同学的git地址. 4.编写Seleniu ...
- Android开发实现QQ三方登录 标签: android开发qq三方登录
本文分为两个部分:一是QQ的授权部分:二是获取用户的基本信息部分 一.授权部分 1.首先,先去腾讯开放平台获取APP ID和APP KEY(未注册腾讯开发者账号的可能需要先注册账号),获取的过程还是还 ...