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 ...
随机推荐
- [Locked] Range Sum Query 2D - Mutable
Range Sum Query 2D - Mutable Given a 2D matrix matrix, find the sum of the elements inside the recta ...
- Linux 下的五种 IO 模型
概念说明 用户空间与内核空间 现在操作系统都是采用虚拟存储器,那么对32位操作系统而言,它的寻址空间(虚拟存储空间)为4G(2的32次方).操作系统的核心是内核,独立于普通的应用程序,可以访问受保护的 ...
- php tcp socket 学习汇总
推荐实例:PHP socket 深入浅出讲解:php的socket通信 基于socket.io的实时消息推送 php socket通信(tcp/udp) PHP向socket服务器收发数据 php实现 ...
- JNI 技术与 Android 应用
1. 什么是 JNI JNI是Java Native Interface的缩写.从Java 1.1开始,JNI标准成为java平台的一部分,它允许Java和其他语言进行交互.JNI一开始为C和C++而 ...
- PagerSlidingTabStrip
https://github.com/jpardogo/PagerSlidingTabStrip
- JAVA Web 之 struts2文件上传下载演示(一)(转)
JAVA Web 之 struts2文件上传下载演示(一) 一.文件上传演示 1.需要的jar包 大多数的jar包都是struts里面的,大家把jar包直接复制到WebContent/WEB-INF/ ...
- C# - 系统类 - Type类
Type类 ns:System Type类封装类型 它的实例提供一个特定类型的数据和函数成员的信息 可以使用Type类实例来调用类型的成员 一般将Type类用于反射 Type类的静态字段如下 Empt ...
- 什么是Cocos2d-x
以下是官方对Cocos2d-x的说明." Cocos2d-x is an open-source mobile 2D game framework, released under ...
- Java代码安全测试解决方案
Java代码安全测试解决方案: http://gdtesting.com/product.php?id=106
- Magento强大的配置系统
Magento的配置系统就像是Magento的心脏,支撑着Magento的运行.这套配置系统掌管着几乎所有"module/model/class/template/etc".它把整 ...