思路: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的更多相关文章

  1. 百练_2409 Let it Bead(Polya定理)

    描述 "Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. As you ca ...

  2. poj 2049 Let it Bead(polya模板)

      Description Cannery Row percent of the target audience insists that the bracelets be unique. (Just ...

  3. poj2409 Let it Bead

                                                                      Let it Bead Time Limit: 1000MS   M ...

  4. POJ1975 Median Weight Bead floyd传递闭包

    Description There are N beads which of the same shape and size, but with different weights. N is an ...

  5. POJ 2409 Let it Bead(polya裸题)

    题目传送:http://poj.org/problem?id=2409 Description "Let it Bead" company is located upstairs ...

  6. 【POJ2409】Let it Bead Pólya定理

    [POJ2409]Let it Bead 题意:用$m$种颜色去染$n$个点的环,如果两个环在旋转或翻转后是相同的,则称这两个环是同构的.求不同构的环的个数. $n,m$很小就是了. 题解:在旋转$i ...

  7. POJ-1975 Median Weight Bead(Floyed)

    Median Weight Bead Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3162 Accepted: 1630 De ...

  8. 珍珠 Median Weight Bead 977

    描述 There are N beads which of the same shape and size, but with different weights. N is an odd numbe ...

  9. Median Weight Bead(最短路—floyed传递闭包)

    Description There are N beads which of the same shape and size, but with different weights. N is an ...

随机推荐

  1. 问题-[DelphiXE2]提示第三控件不存在

    问题情况:在DelphiXE2启动时界面显示加载了控件,并且控件的路径也放在了环境变量中,但打开程序报第三控件不存在. 问题原因:是没有选择要加载的控件. 问题处理:点击Component->I ...

  2. jQuery获取鼠标移动方向2

    (function($) { $.fn.extend({ show: function(div) { var w = this.width(), h = this.height(), xpos = w ...

  3. 51nod1009(1的数目)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1009 题意:中文题诶- 思路:分别考虑各个数位上出现1的次数 ...

  4. FrankFan7你问我答之一

    作者:范军 (Frank Fan) 新浪微博:@frankfan7   微信:frankfan7 最近网友留言很多,你既然看得起我问了,我就说说个人浅见.看看就行了,也别认真. Q:你具体工作是什么? ...

  5. sudo apt-get install gksu

    exmyth@Inspiron-5437:/etc/default$ gksu gedit apport 程序“gksu”尚未安装. 您可以使用以下命令安装:sudo apt-get install ...

  6. Android网络传输中必用的两个加密算法:MD5 和 RSA (附java完毕測试代码)

    MD5和RSA是网络传输中最经常使用的两个算法,了解这两个算法原理后就能大致知道加密是怎么一回事了.但这两种算法使用环境有差异,刚好互补. 一.MD5算法 首先MD5是不可逆的,仅仅能加密而不能解密. ...

  7. Java从设计模式[本场比赛状态转换武器]状态分析(State)模式

    如果我们正在做一个实时战略游戏.我们设计了一个武器,他制作只是当步兵,但他能够切换武器.第一个开关会变成弓箭手,第二个开关导通控股装甲盾牌,第三开关变成步兵--如何实现这一目标切换机构?我们开始思考, ...

  8. Redis学习手册(String数据类型)

    一.概述: 字符串类型是Redis中最为基础的数据存储类型,它在Redis中是二进制安全的,这便意味着该类型可以接受任何格式的数据,如JPEG图像数据或Json对象描述信息等.在Redis中字符串类型 ...

  9. phpmailer使用gmail SMTP的方法

    终于能够通过phpmailer使用gmail账号发送邮件了phpmailer(现在的版本是1.73)是一个很好用的工具,可以很方便的使用php语言发送邮件,支持smtp及验证,我们一直都用它. 但是, ...

  10. Linux内核:关于中断你须要知道的

    1.中断处理程序与其它内核函数真正的差别在于,中断处理程序是被内核调用来对应中断的,而它们执行于中断上下文(原子上下文)中,在该上下文中执行的代码不可堵塞. 中断就是由硬件打断操作系统. 2.异常与中 ...