poj2409 polya定理经典问题

/*
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

置换是翻转:
 分奇偶判断
*/

 

转载于:https://www.cnblogs.com/neverchanje/p/3749367.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值