poj 1286 Necklace of Beads(polya 定理)
来源:互联网 发布:linux squid 4.0 安装 编辑:程序博客网 时间:2024/06/05 01:58
Necklace of Beads
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 7571 Accepted: 3152
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 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.
-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
45-1
Sample Output
2139
Source
Xi'an 2002
[Submit] [Go Back] [Status] [Discuss]
题解:与poj 2409类似。
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#define LL long long using namespace std;LL ans,n,m;LL gcd(LL x,LL y){LL r;while (y){r=x%y;x=y;y=r;}return x;}LL pow(LL num,LL x){LL base=num; LL ans=1;while (x){if (x&1) ans=ans*base;x>>=1;base=base*base;}return ans;}int main(){n=3;while (scanf("%lld",&m)!=EOF){if (m==0){printf("0\n");continue;}if (m==-1) break;ans=0;for (LL i=1;i<=m;i++) ans+=pow(n,gcd(m,i));if (m%2) ans+=pow(n,m/2+1)*m;else ans+=pow(n,m/2+1)*(m/2), ans+=pow(n,m/2)*(m/2);printf("%lld\n",ans/(m*2));}}
0 0
- 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 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 (Polya定理)
- POJ 1286 Necklace of Beads(polya)
- POJ 1286 Necklace of Beads (Polya)
- POJ 1286 Necklace of Beads(polya计数、burnside定理)
- poj1286 Necklace of Beads(polya定理)
- Polya 定理 (附POJ 1286 Necklace of Beads 解题报告)
- POJ 1286-Necklace of Beads(Polya定理-旋转+翻转 串项链)
- poj 1286 Necklace of Beads -----polya计数
- poj 1286 Necklace of Beads (polya)
- poj 1286 Necklace of Beads polya计数
- 小K的农场 差分约束
- 练习三1021
- HDU 5694 BD String
- WinPE基础知识
- mina解决粘包,找不到解码器,数据帧重传的问题
- poj 1286 Necklace of Beads(polya 定理)
- qt各版本下载地址
- fragment onViewCreated
- C语言中fclose函数
- 大蒟蒻の留言板
- HDU 5695 Gym Class
- 线段树模板
- 分糖果 差分约束
- 【POJ 1721】CARDS(置换群)