码迷,mamicode.com
首页 > 其他好文 > 详细

poj2409 polya定理经典问题

时间:2014-05-26 02:26:24      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:des   style   class   blog   c   code   

bubuko.com,布布扣
/*
ID: neverchanje
PROG:
LANG: C++11
*/
#include<vector>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<set>
#include<queue>
#include<map>
#define INF 0Xfffffffff
#define st_size (1<<18)-1
#define maxn
typedef  long long ll;
using namespace std;

int c,s;
ll pow[36];

int gcd(int a,int b){
    if(b==0)    return a;
    return gcd(b,a%b);
}

int main(){
//    freopen("a.txt","r",stdin);
//    freopen(".out","w",stdout);
    while(cin>>c>>s){
        if(c==0 && s==0)  break;

        pow[0]=1;
        for(int i=1;i<=s;i++)    pow[i]=pow[i-1]*c;

        int res=0;
        for(int i=1;i<=s;i++)    res+=pow[gcd(s,i)];

        if(s&1)    res += s*pow[s/2+1];
        else res += s/2*pow[s/2]+s/2*pow[s/2+1];

        printf("%d\n",res/(s*2));
    }
    return 0;
}

/*
DESCRIPTION:
项链的旋转是polya定理的基本问题
polya定理:
    sum(C(f))/|f| //burnside引理
    C(f)=k^m(f)   //k为颜色数,m(f)为循环数

置换是旋转:
给项链编号0,1,2,...s-1
可连续旋转0,1,2,3,....,s-1个珠子,对应|f|=s个置换
每个置换都有k=c

对s=6
转6(即不转) m(f)=6
转1 m(f)=1
转2 m(f)=2
转3 m(f)=3
转4 m(f)=2
转5 m(f)=1
可发现m(f)=gcd(i,s) //i表示转几个
m(f)<=s

置换是翻转:
 分奇偶判断
*/
bubuko.com,布布扣

 

poj2409 polya定理经典问题,布布扣,bubuko.com

poj2409 polya定理经典问题

标签:des   style   class   blog   c   code   

原文地址:http://www.cnblogs.com/neverchanje/p/3749367.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!