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

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

优质内容筛选与推荐>>
1、APM-全链路追踪
2、简单搭建http服务器-HttpListener使用
3、记忆力
4、2018.7.19训练赛总结
5、【Express系列】第3篇——接入mysql


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号