您的位置:首页 > 其它

poj 2409(polya定理模板)

2015-12-30 21:04 357 查看
旋转加翻转

#include <iostream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define maxn 1200
#define eps 1e-8
int gcd(int n,int m)
{
if (m == 0) {
return n;
}
return gcd(m,n%m);
}
int c,s;
int main()
{
while (cin>>c>>s&&c&&s) {
long long ans = 0;
for (int i = 1; i<=s; i++) {
ans += pow(c, gcd(s, i));
}
if (s&1) {
ans += s*pow(c, s/2+1);
}
else
ans += s/2*pow(c, (s+2)/2)+s/2*pow(c, s/2);
ans /= s*2;
cout<<ans<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: