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 ;
}
题目大意:给出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 ;
}
相关文章推荐
- 【iOS】MD5加密与网络数据安全
- Apache Shiro 使用手册(一)Shiro架构介绍
- 分布数数据库事物
- Linux内核抢占实现机制分析
- java 验证码之 Jcaptcha;springMVC 验证码
- openflow详解
- 为STARUML写的自动生成文档脚本
- EL表达式截取字符串
- 网络请求之GET、POST请求
- Spring MVC学习----------处理Ajax请求
- JQuery 可见性过滤选择器
- http错误码
- git 实用操作
- 为STARUML写的自动生成文档脚本 分类: 开发工具 2015-07-28 10:27 9人阅读 评论(0) 收藏
- 01背包问题
- 机器学习各种算法结果可视化比对
- Android闪屏问题如何Debug
- 创建子类对象时,父类构造函数中调用被子类重写的方法为什么调用的是子类的方法,而被子类重载的方法不会调用?
- 用 Windows API “GetAdaptersInfo” 获取 MAC 时遇到的问题
- StartUML自动生成代码