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;
}

  

时间: 2024-08-25 06:37:03

POJ 1286的相关文章

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

http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜了一篇论文Pólya原理及其应用看了看polya究竟是什么东东.它主要计算所有互异的组合的个数.对置换群还是似懂略懂.用polya定理解决这个问题的关键是找出置换群的个数及哪些置换群,每种置换的循环节数.像这样的不同颜色的珠子构成项链的问题能够把N个珠子看成正N边形. Polya定理:(1)设G是p

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

Necklace of Beads 大意:3种颜色的珠子,n个串在一起,旋转变换跟反转变换如果相同就算是同一种,问会有多少种不同的组合. 思路:正规学Polya的第一道题,在楠神的带领下,理解的还算挺快的,代码没什么好说的,裸的Polya,也不需要优化. 1 /************************************************************************* 2 > File Name: POJ1286.cpp 3 > Author: GLSil

[ACM] POJ 1286 Necklace of Beads (Polya计数,直接套公式)

Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6547   Accepted: 2734 Description Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n < 24 ). If the repetitions that are pro

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

http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子,要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后相同的属于同一种方法. polya计数. 搜了一篇论文Pólya原理及其应用看了看polya到底是什么东东,它主要计算全部互异的组合的个数.对置换群还是似懂略懂.用polya定理解决问题的关键是找出置换群的个数及哪些置换群,每种置换的循环节数.像这种不同颜色的珠子构成项链的问题可以把N个珠子看成正N边形. Polya定理:(1)设G是p个对象

【POJ 1286】Necklace of Beads(polya定理)

[POJ 1286]Necklace of Beads(polya定理) Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7550   Accepted: 3145 Description Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n <

POJ 1286 【POLYA】

题意: 给你三种颜色的珠子,每次给你N,问在旋转,翻转之后视作相同的情况下,能组成多少种不同的项链. 思路: 让我们借这道题拯救一下我对POLYA定理的理解... sigma(m^(gcd(i,n))) 以上是在旋转的时候计数的和,其中m是颜色的数量,n是项链的长度. 一下考虑翻转的情况: 当n是偶数的时候, 有n/2种情况循环节的数量是n/2+1,有n/2种情况是n/2. 当n是奇数的时候, 有n种情况是循环节的数量是n/2+1 别忘了最后要除以循环节总的种类数!!! 坑点: 这题n可能等于0

poj 1286 Necklace of Beads

Necklace of Beads 题意:用三种颜色给长度为n(n < 24)的环状手镯涂色,若能通过旋转或翻转得到则表示为同一种,问不同种涂色方案为多少? 思路:纯粹的等价类计算问题: 重点:对旋转和翻转转化为置换操作: 旋转:对间隔的长度进行枚举,即0 <= i < n:这样循环节就为n/gcd(i,n);直接弄成3的幂次方求和即可: 翻转:分奇偶,再求出对称轴的个数和每种情况下循环节的个数即可: 上面求出的a+b只是不动点的个数总和,最后要除以总的置换的个数即2n; #includ

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

Description Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n < 24 ). If the repetitions that are produced by rotation around the center of the circular necklace or reflection to the axis of symmetry ar

数学计数原理(P&#243;lya):POJ 1286 Necklace of Beads

Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7763   Accepted: 3247 Description Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n < 24 ). If the repetitions that are pro

poj 1286&amp;&amp;poj2409 Polya计数 颜色匹配

#include <iostream> #include <math.h> using namespace std; #define LL long long LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; } LL polya(LL n) { LL ret = 0; for(LL i = 0; i < n; i++) ret += pow(3, gcd(i, n)); //flip them... if( n &