您的位置:首页 > 其它

poj2409--Let it Bead(置换群+polya奇数)

2015-07-28 10:27 369 查看
题目链接:点击打开链接

题目大意:给出m种颜色的小球,现在要求用n个串成一个环,经过旋转翻转后,能形成多少个不同的环。

参考:点击打开链接

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std ;
#define LL __int64
LL gcd(LL a,LL b) {
return b == 0 ? a : gcd(b,a%b) ;
}
LL pow(LL x,LL k) {
if( k == 1 ) return x ;
LL s = pow(x,k/2) ;
s = s*s ;
if( k%2 ) s *= x ;
return s ;
}
int main() {
LL n , m , i , ans , num ;
while( scanf("%I64d %I64d", &m, &n) && n+m != 0 ) {
ans = 0 ;
for(i = 0 ; i < n ; i++)
ans += pow(m,gcd(n,i)) ;
if( n%2 ) {
ans += n*pow(m,n/2+1) ;
}
else {
ans += n/2*pow(m,n/2) ;
ans += n/2*pow(m,n/2+1) ;

}
printf("%I64d\n", ans/(n*2)) ;
}
return 0 ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: