您的位置:首页 > 其它

poj-2409(polya定理模板)

2015-01-27 16:41 323 查看
题意:给n种颜色和m个小球,问有多少种不同的方案!

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;

int n, m;

int gcd(int a, int b)
{
    b = b % a;
    while (b)
    {
        a = a % b;
        swap(a, b);
    }
    return a;
}

int main()
{
    while (scanf("%d%d", &n, &m), n | m)
    {
        int ans = 0;
        for (int i = 1; i <= m; i++)
            ans += pow(n, gcd(i, m));//旋转置换
        if (m & 1)
            ans += m * pow(n, m / 2 + 1);
        else
            ans += m / 2 * pow(n, m / 2) + m / 2 * pow(n, m / 2 + 1);//翻转置换
        ans /= m * 2;
        printf("%d\n", ans);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: