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. ...
随机推荐
- tomcat设置编码utf8
1. Java类: CharacterEncodingFilter import javax.servlet.*; import java.io.IOException; public ...
- Android Touch事件分发过程
虽然网络上已经有非常多关于这个话题的优秀文章了,但还是写了这篇文章,主要还是为了加强自己的记忆吧,自己过一遍总比看别人的分析要深刻得多.那就走起吧. 简单演示样例 先看一个演示样例 : 布局文件 : ...
- CSDN高校俱乐部第二届战神杯第二题题解
两个人玩一个数字游戏,给定两个正整数A,B,两个人轮流从一个数中减去另外一个数的正数倍.要保证结果非负, 首先得到0的人获胜. 比如:30 8经过一步操作能够变为22 8 或者14 8 或者 6 8. ...
- 在 Eclipse 中使用 C++
安装 安装Eclipse Eclipse下载页 能够选择Eclipse IDE for C/C++ Developers(内置CDT插件) 也能够选择安装其它版本号之后再安装CDT插件. 安装CDT插 ...
- MAME 0.201 发布,重温童年的街机模拟器
MAME 0.201 已发布,MAME 最初是街机模拟器,随着时间的推移,MAME 吸收了姊妹项目 MESS(多机种模拟器超级系统),所以 MAME 现在还记录了各种各样的(大多是老式的)电脑游戏.掌 ...
- C# Keywords - as
记录一下在日常开发过程中遇到的一些C# 基础编程的知识! 希望以后能用的着.知识是在平常的开发过程中去学到的.只有用到了,你才能深入的理解它,并用好它. 本资料来源于:MSND 下面是一些相关的cod ...
- POJ 1384 Piggy-Bank DP
一个完全背包 很裸,对于我这种DP渣渣都能1A.. // by SiriusRen #include <cstdio> #include <cstring> #include ...
- pyspider architecture--官方文档
原文地址:http://docs.pyspider.org/en/latest/Architecture/ Architecture This document describes the reaso ...
- JQuery学习系列篇(二)
1.事件切换函数 hover([over],out); over鼠标移动到元素上要触发的函数,out鼠标移出元素要触发的函数. 2.togger 如果元素是可见的,切换为隐藏的:如果元素是隐藏的,切换 ...
- UWP 开发相关
OCR 识别问题 ocr.OcrEngine.availableRecognizerLanguages 如果 length 只有 1,有可能只能识别英文,需要安装中文语言包~