POJ 1286 Necklace of Beads Polya .
2016-08-15 14:01
393 查看
题目地址:http://poj.org/problem?id=1286
旋转+翻转,裸的算法
旋转+翻转,裸的算法
#include<iostream> #include<cstdio> #include<cmath> using namespace std; typedef long long LL; int gcd(int a,int b) { if(b==0) return a; return gcd(b,a%b); } int euler_phi(int n) { int res=1; for(int i=2;i*i<=n;i++) if(n%i==0) { //说明i|n n/=i,res*=i-1; while(n%i==0) n/=i,res*=i; //说明i^2|n } if(n>1) res*=n-1; return res; } LL polya(int n) { LL tot=0; //方案数 for(int i=1;i<=n;i++) tot+=pow(3,gcd(n,i)); tot/=n; if(n%2!=0) tot+=pow(3,(n+1)/2); //odd else tot+=(pow(3,n/2)+pow(3,n/2+1))/2; return tot/2; } int main() { int n; while(cin>>n&&n!=-1) if(n==0) cout<<0<<endl; else cout<<polya(n)<<endl; return 0; }
相关文章推荐
- [ACM] POJ 1286 Necklace of Beads (Polya计数,直接套公式)
- poj 1286 Necklace of Beads (组合数学 polya计数法)
- poj 2409 Let it Bead && poj 1286 Necklace of Beads(Polya定理)
- POJ 1286 Necklace of Beads(Polya简单应用)
- POJ 1286 Necklace of Beads(Polya定理)
- POJ 1286 A - 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 & poj 2409 Let it Bead(初涉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 Necklace of Beads 1286 (polya定理)置换群
- POJ 1286 Necklace of Beads(polya计数、burnside定理)
- poj 1286 Necklace of Beads (polya)
- poj 1286 Necklace of Beads (polya)
- poj1286 Necklace of Beads(polya)
- poj 1286 Necklace of Beads【polya定理+burnside引理】