本文主要是介绍poj1286 Necklace of Beads【裸polya】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
很裸的polya,不过我看polya看了很久
吉大ACM模板里面也有
#include <cstdio>
#include <cmath>
#include <iostream>
using namespace std;
long long gcd(long long a,long long b)
{return b==0?a:gcd(b,a%b);
}
int main()
{#ifndef ONLINE_JUDGE//freopen("G:/1.txt","r",stdin);//freopen("G:/2.txt","w",stdout);#endiflong long p[33];p[0]=1;for(long long i=1;i<=24;i++){p[i]=p[i-1]*3;//cout<<p[i]<<endl;}long long res=0;long long s;while(cin>>s){if(s==-1)break;if(s==0){cout<<"0\n";continue;}long long res=s&1?s*p[s/2+1]:(s/2)*(p[s/2]+p[s/2+1]);for(long long k=1;k<=s;k++){res+=p[gcd(k,s)];}res/=2*s;cout<<res<<'\n';}return 0;
}
这篇关于poj1286 Necklace of Beads【裸polya】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!