美文网首页
poj2409 Burnside引理 + Polya定理(圆)

poj2409 Burnside引理 + Polya定理(圆)

作者: 暖昼氤氲 | 来源:发表于2019-12-15 16:26 被阅读0次
/*
Time:2019.12.15
Author: Goven
type:Burnside引理 + Polya定理(圆)
ref:
https://www.cnblogs.com/AKCqhzdy/p/7593704.html
https://blog.csdn.net/lianai911/article/details/47804663
*/
#include<iostream>

using namespace std;

int gcd (int a, int b) {
    return b ? gcd(b, a % b) : a;
}

int quick_pow (int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1) res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int main()
{
    int c, s;
    while (cin >> c >> s) {
        if (!c && !s) break;
        int res = 0;
        //旋转变换
        for (int i = 1; i <= s; i++) res += quick_pow(c, gcd(i, s)); 
        //翻转变换
        if (s & 1) {
            res += s * quick_pow(c, (s + 1) / 2);
        } 
        else {
            res += s / 2 * quick_pow(c, s / 2);
            res += s / 2 * quick_pow(c, s / 2 + 1);
        }
        res /= 2 * s;
        cout << res << endl;
    } 
    return 0;
}

相关文章

网友评论

      本文标题:poj2409 Burnside引理 + Polya定理(圆)

      本文链接:https://www.haomeiwen.com/subject/afxlnctx.html