题目描述:
用三种颜色给一条长为$n$的项链染色,要求染色方案不同。
两种方案不同即旋转或翻转后不相同。
题解:
这道题用到$Burnside$引理的升级版$Polya$定理。
$Polya$定理:一种轨道的不动点数=颜色数^组数。
代码:
#include<cstdio> typedef long long ll; int n; ll bas[25]; int gcd(int a,int b) { return b?gcd(b,a%b):a; } int main() { bas[0] = 1; for(int i=1;i<=23;i++) bas[i] = bas[i-1]*3; while(1) { scanf("%d",&n); if(n==-1)break; if(!n) { puts("0"); continue; } ll ans = 0; for(int i=1;i<=n;i++) ans += bas[gcd(i,n)]; if(n&1) { ans += 1ll*n*bas[(n+1)>>1]; }else { ans += 1ll*(n>>1)*bas[n>>1]+1ll*(n>>1)*bas[(n>>1)+1]; } printf("%lld ",ans/(2ll*n)); } return 0; }