POJ1286:Necklace of Beads(POLYA定理应用)
2012-11-23 18:38
561 查看
Necklace of Beads
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 are all neglected, how many different forms of the necklace are there? Input The input has several lines, and each line contains the input data n. -1 denotes the end of the input file. Output The output should contain the output data: Number of different forms, in each line correspondent to the input data. Sample Input 4 5 -1 Sample Output 21 39 Source Xi'an 2002 |
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
typedef long long ll;
using namespace std;
int gcd(int a,int b)
{
if(a%b==0)
return b;
return gcd(b,a%b);
}
int main()
{
int n;
while(scanf("%d",&n))
{
if(n==-1)
break;
if(n==0)//note
{
printf("0\n");
continue;
}
ll ans=0;
int i;
for(i=1;i<=n;i++)
{
ans+=(ll)(pow(3.0,gcd(n,i)));
}
if(n&1)
{
ans+=(ll)(n*pow(3.0,n/2+1));
}
else
{
ans+=(ll)(n/2*pow(3.0,n/2)+n/2*pow(3.0,n/2+1));
}
printf("%lld\n",ans/(2*n));
}
}
//
POLYA定理的应用
注意:
1特殊考虑n==0的情况,否则会runtime error
1结果要用long long.
相关文章推荐
- poj Necklace of Beads 1286 (polya定理)置换群
- POJ 1286-Necklace of Beads(Polya定理-旋转+翻转 串项链)
- 【POJ 1286】Necklace of Beads(polya定理)
- 【POJ 1286】Necklace of Beads(Polya 定理)
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
- POJ 1286 Necklace of Beads(Polya简单应用)
- poj_1286 Necklace of Beads(置换群Polya定理)
- poj 1286 Necklace of Beads(Polya定理)
- POJ 1286 Necklace of Beads (Polya定理)
- POJ 1286 Necklace of Beads(polya计数、burnside定理)
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
- poj 2409 Let it Bead && poj 1286 Necklace of Beads(Polya定理)
- poj 1286 Necklace of Beads(polya 定理)
- POJ 1286 Necklace of Beads(Polya简单应用)
- poj1286 Necklace of Beads(polya定理)
- Polya 定理 (附POJ 1286 Necklace of Beads 解题报告)
- poj 1286 Necklace of Beads【polya定理+burnside引理】
- POJ 1286 Necklace of Beads(Polya定理)
- POJ 题目1286 Necklace of Beads(Polya定理)
- poj 1286 Necklace of Beads (组合数学 polya计数法)