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 ...
随机推荐
- C++中构造函数和析构函数调用的时机
今天看书忽然对这个地方有点模糊,尤其是析构函数在调用默认的析构函数和用户自己覆写的析构函数的时候有点意识模糊呢.写段代码总结下 #include <iostream> using name ...
- unix时间戳和localtime
今天看代码的时候看到这么一段 void user::setHelpday() { int time = ::getTickCount(); m_helpday = (time +( * ))/( * ...
- Esper系列(十)NamedWindow语法delete、Select+Delete、Update
On-Delete With Named Windows 功能:在Named Windows中删除事件. 格式: 1 , 4 field_b = win.field_a, 5 field_ ...
- HDOJ-ACM1022(JAVA)
这道题:是模拟出栈,判断出栈顺序的可能性. 基本上大家的做法都是直接模拟栈的出栈入栈并将顺序用0,1序列来表示,我暂时没想到什么好的思路. import java.util.*; import jav ...
- shiro权限控制方式
1.基于配置文件(*.ini)[常用jdbcRealm.ini] 2.基于注解的配置 3.基于jsp标签的配置(需要导入对应的标签jar包) 权限包含: 是否为特定用户 是否为特定角色 是否拥有特定操 ...
- 在Java中如何用String类中的indexof方法得到一个词的出现频率
public class Test{ public static void main(String[] args) { String s="hello jack hello look me ...
- Linux 设置系统时间和日期 API
嵌入式Linux 设置时间和日期 API ,它是busybox要提取的源代码. Linux设置时间和日期的步骤: 1. 设置系统时间和日期: 2. 该系统的时间和日期,同步到硬件. #include ...
- sqrt 源代码
stap -v -e 'probe process("/usr/local/mysql56/bin/mysqld").function("*@/usr/src/mysql ...
- 定制操作(传递函数或lambda表达式)
很多算法都会比较输入序列中的元素.默认情况下,这类算法使用元素类型的<或==运算符完成比较.标准库还为这些算法定义了额外的版本,允许我们提供自己定义的操作来代替默认运算符. 例如,sort算法默 ...
- find which process occupy the PORT
mac : lsof -i:8080 linux : netstat -anltp | grep 8080