zoj1873 Let it Bead
思路:polya裸题,如果是旋转,对于旋转i格的循环节长度len=lcm(i,n)/i,个数就是n/len=gcd(i,n);如果是翻转,奇数个点对称轴就是一个点一条边,那么循环节个数即n/2+1,
偶数个点有n/2条对称轴穿过两个点,循环节个数是n/2+1,n/2条对称轴穿过两条边,循环节个数就是n/2,然后直接套polya公式即可。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std; int n,m; int gcd(int a,int b){
return b==?a:gcd(b,a%b);
} long long power(int a,int k){
if (k==) return ;
if (k==) return a;
int x=power(a,k/),ans=x*x;
if (k&) ans*=a;
return ans;
} int main(){
while (scanf("%d%d",&m,&n)!=EOF){
if (n== && m==) break;
long long ans=;
for (int i=;i<=n;i++) ans+=power(m,gcd(n,i));
if (n&) ans+=n*power(m,n/+);else ans+=n/*power(m,n/)+n/*power(m,n/+);
printf("%lld\n",ans/(n*));
}
}
zoj1873 Let it Bead的更多相关文章
- 百练_2409 Let it Bead(Polya定理)
描述 "Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. As you ca ...
- poj 2049 Let it Bead(polya模板)
Description Cannery Row percent of the target audience insists that the bracelets be unique. (Just ...
- poj2409 Let it Bead
Let it Bead Time Limit: 1000MS M ...
- POJ1975 Median Weight Bead floyd传递闭包
Description There are N beads which of the same shape and size, but with different weights. N is an ...
- POJ 2409 Let it Bead(polya裸题)
题目传送:http://poj.org/problem?id=2409 Description "Let it Bead" company is located upstairs ...
- 【POJ2409】Let it Bead Pólya定理
[POJ2409]Let it Bead 题意:用$m$种颜色去染$n$个点的环,如果两个环在旋转或翻转后是相同的,则称这两个环是同构的.求不同构的环的个数. $n,m$很小就是了. 题解:在旋转$i ...
- POJ-1975 Median Weight Bead(Floyed)
Median Weight Bead Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3162 Accepted: 1630 De ...
- 珍珠 Median Weight Bead 977
描述 There are N beads which of the same shape and size, but with different weights. N is an odd numbe ...
- Median Weight Bead(最短路—floyed传递闭包)
Description There are N beads which of the same shape and size, but with different weights. N is an ...
随机推荐
- Microsoft SQL Server Data Tools - Business Intelligence for Visual Studio 2013 http://www.microsoft.com/en-us/download/details.aspx?id=42313
Microsoft SQL Server Data Tools - Business Intelligence for Visual Studio 2013 http://www.microsoft. ...
- Redis在PHP中的基本使用案例
下载http://www.oschina.net/p/redis 解压后里面有:lib 源文件 .examples 例子.test测试 将lib目录拷贝到你的项目中,就可以开始你的predis操作了. ...
- HTML5初学者福利!11个在线学习网站推荐
HTML5初学者福利!11个在线学习网站推荐 HTML5的强大及流行趋势,让更多的人想要系统的对它进行学习.而大多数人获取HTML5知识的重要途径都是网络,不过面对五花八门的搜索结果,是不是觉得摸不着 ...
- 一步一步学android控件(之十六)—— CheckBox
根据使用场景不同,有时候使用系统默认的CheckBox样式就可以了,但是有时候就需要自定义CheckBox的样式.今天主要学习如何自定义CheckBox样式.在CheckBox状态改变时有时需要做一些 ...
- Cocos2d-x MultipleTouch & CCControllButton's confusion
在cocos2dx的程序设计中有时候会遇到需要多点触摸的功能,下面先介绍一下在cocos2dx中多点触摸的一般规则,然后介绍我遇到的一个有关多点触摸的情景的解决方案. (一)使用多点触摸规则: 关于多 ...
- [caffe]深度学习之图像分类模型VGG解读
一.简单介绍 vgg和googlenet是2014年imagenet竞赛的双雄,这两类模型结构有一个共同特点是go deeper.跟googlenet不同的是.vgg继承了lenet以及alexnet ...
- oncopy和onpaste
在Javascript中,有对应的事件能够监听复制和粘贴,那就是oncopy和onpaste. oncopy: demo: <body oncopy="alert('不能复制');re ...
- 理解 MEF
1.它解决什么问题? 考虑下面的需求,甲程序员对外暴露接口,内部提供实现.乙程序员使用甲提供的接口,根据面向接口编程的原则,乙关联一个接口类型的引用.正常情况下,乙要使用甲的实现,必须实例化一个具体对 ...
- SecureCRT学习之道:SecureCRT经常使用快捷键设置与字体设置方法
1:假设不想每次登陆都输入password,能够在你打开的session里邮件session option->login action 选中automate logon 双击ogin 和assw ...
- poj 3253 Fence Repair(优先队列+哈夫曼树)
题目地址:POJ 3253 哈夫曼树的结构就是一个二叉树,每个父节点都是两个子节点的和. 这个题就是能够从子节点向根节点推. 每次选择两个最小的进行合并.将合并后的值继续加进优先队列中.直至还剩下一个 ...