Polya定理:
设G={a1,a2,...,a|G|}是N={1,2,...,N}上的置换群,现用m种颜色对这N个点染色,则不同的染色方案数为
S=(mc1+mc2+...+mc|G|)/|G|
旋转:
n个点顺时针(或逆时针)旋转i个位置的置换,轮换个数为gcd(n,i)
翻转:
n为偶数且对称轴不过顶点:轮换个数为n/2
n为偶数且对称轴过顶点:轮换个数为n/2+1
n为奇数:轮换个数为(n+1)/2
CODE:
/*Polya定理*/
/*置换群:旋转+翻转*/
/*AC代码:0ms*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <memory.h>
#include <cmath>
#define M 3
using namespace std;
int gcd(int a,int b)
{
int r;
while(b>0)
{
r=a%b;
a=b;
b=r;
}
return a;
}
int N;
int main()
{
int i;
__int64 c,ans,temp;
while(scanf("%d",&N)!=EOF)
{
if(N==-1) break;
if(N==0) {printf("0\n");continue;}
ans=0;
for(i=0;i<N;i++)
{
c=gcd(N,i);
ans+=(__int64)pow((double)M,(double)c);
}
if(N%2)
{
c=(N+1)/2;
temp=(__int64)pow((double)M,(double)c);
ans+=N*temp;
}
else
{
c=N/2;
temp=(__int64)pow((double)M,(double)c);
ans+=(N/2)*temp;
temp*=M;
ans+=(N/2)*temp;
}
printf("%I64d\n",ans/2/N);
}
return 0;
}