poj 1286 Necklace of Beads 夜

http://poj.org/problem?id=1286

polya    burnside

难了不会 会了不难

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<cmath>
#define LL long long

using namespace std;

int gcd(int a,int b)
{
    if(a%b==0)
    return b;
    return gcd(b,a%b);
}
LL ploya(int n,int m)
{
    if(n==0)
    return 0;
    LL ans=0;
    for(int i=1;i<=n;++i)
    {
        ans+=(LL)(pow(double(m),gcd(n,i)));
    }//cout<<ans<<endl;
    if(n%2==1)
    {
        ans+=(n*((LL)(pow(double(m),(n+1)/2))));
    }else
    {
        ans+=(n/2*(LL)(pow(double(m),n/2)+pow(double(m),(n+2)/2)));
    }
    return ans/n/2;
}
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        if(n==-1)
        break;
        cout<<ploya(n,3)<<endl;
    }
    return 0;
}

  

原文地址:https://www.cnblogs.com/liulangye/p/2607671.html