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 ...
随机推荐
- HDOJ-ACM1012(JAVA)
这道题很简单,主要是弄懂题意和注意输出: 输出的完整结果如下: n e - ----------- 0 1 1 2 2 2.5 3 2.666666667 4 2.708333333 5 2.7166 ...
- POJ1836 - Alignment(LIS)
题目大意 一队士兵排成一条直线,问最少出队几个士兵,使得队里的每个士兵都可以看到又端点或者左端点 题解 从左往右搞一遍LIS,然后从右往左搞一遍LIS,然后枚举即可... 代码: #include&l ...
- ASP.NET--ListBox初始化时设置多个选中项
public void SetSelectedListItem(ListBox lst, List<DBServerIPBind> source) { ; i < source.Co ...
- A list of base boxes for Vagrant - Vagrantbox.es
Create image server with nginx + lua (Openresty) + graphicsmagick (Part I) | Ian's PhotograPhy Blog ...
- POJ 2115 C Looooops(扩展欧几里得)
辗转相除法(欧几里得算法) 时间复杂度:在O(logmax(a, b))以内 int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a ...
- 用java面向对象的思想实现的汉诺塔问题
package hanoi.com; public class Disc { private String name; private int level; public Disc(){ name = ...
- [二]JFreeChart实践一
生成一张简单的图片 java代码: package com.lxl.chart; import javax.servlet.http.HttpSession; import org.jfree.cha ...
- JBPM学习(四):执行流程实例
概念: ProcessInstance,流程实例:代表流程定义的一次执行.如:张三昨天按请假流程请了一次假.一个流程实例包括了所有运行阶段,其中最典型的属性就是跟踪当前节点的指针,如下图. Execu ...
- Android代码中动态设置图片的大小(自动缩放),位置
项目中需要用到在代码中动态调整图片的位置和设置图片大小,能自动缩放图片,用ImageView控件,具体做法如下: 1.布局文件 <RelativeLayout xmlns:android=&qu ...
- 安装SQL Server提示“重叠的IO操作正在进行”解决
单位新做了一个虚机.打算部署一套.Net SQL 的系统 系统是Server 2008 R2,机器除了系统,其它软件都没有. 所以须要安装SQL Server啊,.Net环境啊.配置IIS== 恰巧的 ...