HDU3923-Invoker-polya n次二面体
polya定理。等价类的个数等于∑颜色数^置换的轮换个数
不可翻转的串当中。直接计算∑m^(gcd(n,i)) ,这里gcd(n,i)就是第i个置换的轮换数。
翻转的情况再分n奇偶讨论。
n次二面体都是这个套路。
/*--------------------------------------------------------------------------------------*/ #include <algorithm>
#include <iostream>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map> //debug function for a N*M array
#define debug_map(N,M,G) printf("\n");for(int i=0;i<(N);i++)\
{for(int j=;j<(M);j++){\
printf("%d",G[i][j]);}printf("\n");}
//debug function for int,float,double,etc.
#define debug_var(X) cout<<#X"="<<X<<endl;
#define LL long long
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
/*--------------------------------------------------------------------------------------*/
using namespace std; int N,M,T;
const LL MOD = 1e9+; LL pow_mod(LL x,LL cnt)
{
LL base = x,res = ;
while(cnt)
{
if(cnt&) {res*=base;res%=MOD;}
base *= base;base %= MOD;
cnt >>= ;
}
return res%MOD;
}
LL inv(LL x,LL m)
{
return pow_mod(x,m-);
}
LL polya(LL n,LL m)
{
LL res = ;
for(int i=;i<=n;i++)
{
res += pow_mod(m,__gcd((LL)i,n));
res %= MOD;
} if(n&) res += n*pow_mod(m,n/+);
else res += (n*pow_mod(m,n/))%MOD*inv(,MOD)%MOD + (n*pow_mod(m,n/+))%MOD*inv(,MOD)%MOD ; res %= MOD;
res *= inv(*n,MOD); return res%MOD;
} int main()
{
scanf("%d",&T);
int cas = ;
while(T--)
{
scanf("%d%d",&M,&N);
printf("Case #%d: %lld\n",++cas,polya(N,M));
}
}
HDU3923-Invoker-polya n次二面体的更多相关文章
- HDU 3923 Invoker(polya定理+乘法逆元(扩展欧几里德+费马小定理))
Invoker Time Limit : 2000/1000ms (Java/Other) Memory Limit : 122768/62768K (Java/Other) Total Subm ...
- HDU 3923 Invoker(polya定理+逆元)
Invoker Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 122768/62768 K (Java/Others)Total Su ...
- HDU 3923 Invoker 【裸Polya 定理】
参考了http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 的模板 对于每一种染色,都有一个等价群,例如旋转, ...
- POJ2154 Color【 polya定理+欧拉函数优化】(三个例题)
由于这是第一天去实现polya题,所以由易到难,先来个铺垫题(假设读者是看过课件的,不然可能会对有些“显然”的地方会看不懂): 一:POJ1286 Necklace of Beads :有三种颜色,问 ...
- 《程序设计中的组合数学》——polya计数
我们在高中的组合数学中常常会碰到有关涂色的问题,例如:用红蓝两种颜色给正方形的四个顶点涂色,会有几种不同的方案.在当时,我们下意识的认为,正方形的四个顶点是各不相同的,即正方形是固定的.而实际上我们知 ...
- Polya计数
Let it Bead Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5365 Accepted: 3585 Descr ...
- [ACM] hdu 3923 Invoker (Poyla计数,高速幂运算,扩展欧几里得或费马小定理)
Invoker Problem Description On of Vance's favourite hero is Invoker, Kael. As many people knows Kael ...
- polya/burnside 学习
参考链接: http://www.cnblogs.com/hankers/archive/2012/08/03/2622231.html http://blog.csdn.net/raalghul/a ...
- 【转】Polya定理
转自:http://endlesscount.blog.163.com/blog/static/82119787201221324524202/ Polya定理 首先记Sn为有前n个正整数组成的集合, ...
随机推荐
- [LoadRunner]性能测试实践_Hessian协议脚本编写2
协议选取和运行配置请参考:http://www.cnblogs.com/whylaughing/p/5430821.html 这次直接贴代码让大家参考: import lrapi.lr; import ...
- Effective Java 57 Use exceptions only for exceptional conditions
Principle Exceptions are, as their name implies, to be used only for exceptional conditions; they sh ...
- linux下重启oracle服务:监听器和实例
一.在Linux下重启Oracle数据库及监听器: 方法1: 用root以ssh登录到linux,打开终端输入以下命令: cd $ORACLE_HOME #进入到oracle的安装目录 dbstart ...
- ELK 信息统计分析-2
Range 按数值类型的字段聚合统计 { "query": { "match_all": {} }, "aggs": { "ter ...
- find命令中参数perm的用法
按照文件权限模式用-perm选项,按文件权限模式来查找文件的话.最好使用八进制的权限表示法.如在当前目录下查找文件权限位为755的文件,即文件属主可以读.写.执行,其他用户可以读.执行的文件,可以用: ...
- UVA 10827 Maximum sum on a torus (LA)
算法入门经典训练指南88页练习 ::这道题只要把原矩阵扩大4倍,那么其跟最大子矩阵的题目就很类似,把二维转化成一维,求最大的序列和,不过这个序列的长度不能超过n. 长度不能超过n? 那这道题又跟hdu ...
- How to use python remove the '^M' when copy words from Windows to Linux
今天帮同事用Python写了一个小工具,实现了在linux下批量文件名和去掉windows 文件到linux过程中产生^M的脚本,代码如下: !/opt/exptools/bin/python imp ...
- yum 安装包的用法
最近刚爆出linux下glibc有重大漏洞,修复方案为升级glibc库 RHEL/CentOS下一键即可修复 : sudo yum update glibc .或者如果本地有rpm包 直接 rpm - ...
- LAMP编译参数查看
Linux下查看Nginx.Napache.MySQL.PHP的编译参数的命令如下: 1.nginx编译参数:#/usr/local/nginx/sbin/nginx -V2.apache编译参数:# ...
- ZooKeeper系列3:ZooKeeper命令、命令行工具及简单操作
问题导读1.ZooKeeper包含哪些常用命令?2.通过什么命令可以列出服务器 watch 的详细信息?3.ZooKeeper包含哪些操作?4.ZooKeeper如何创建zookeeper? 常用命令 ...