HDU 3923 Invoker(polya定理+逆元)
Invoker
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 122768/62768 K (Java/Others)
Total Submission(s): 907 Accepted Submission(s): 364
In his new map, Kael can control n kind of elements and he can put m elements equal-spacedly on a magic ring and combine them to invoke a new skill. But if a arrangement can change into another by rotate the magic ring or reverse the ring along the axis, they will invoke the same skill. Now give you n and m how many different skill can Kael invoke? As the number maybe too large, just output the answer mod 1000000007.
For each test case: give you two positive integers n and m. ( 1 <= n, m <= 10000 )
3 4
1 2
Case #2: 1
For Case #1: we assume a,b,c are the 3 kinds of elements.
Here are the 21 different arrangements to invoke the skills
/ aaaa / aaab / aaac / aabb / aabc / aacc / abab /
/ abac / abbb / abbc / abcb / abcc / acac / acbc /
/ accc / bbbb / bbbc / bbcc / bcbc / bccc / cccc /
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <math.h>
using namespace std;
const int MOD= 1e9+; long long pow_m(long long a,int n)
{
long long ret = ;
long long temp = a%MOD;
while(n)
{
if(n&)
{
ret *= temp;
ret %= MOD;
}
temp *= temp;
temp %= MOD;
n >>= ;
}
return ret;
}
int gcd(int a,int b)
{
if(b == )return a;
return gcd(b,a%b);
}
//******************************
//返回d=gcd(a,b);和对应于等式ax+by=d中的x,y
long long extend_gcd(long long a,long long b,long long &x,long long &y)
{
if(a==&&b==) return -;//无最大公约数
if(b==){x=;y=;return a;}
long long d=extend_gcd(b,a%b,y,x);
y-=a/b*x;
return d;
}
//*********求逆元素*******************
//ax = 1(mod n)
long long mod_reverse(long long a,long long n)
{
long long x,y;
long long d=extend_gcd(a,n,x,y);
if(d==) return (x%n+n)%n;
else return -;
} int main()
{
int T;
int m,n;
scanf("%d",&T);
int iCase = ;
while(T--)
{
iCase++;
scanf("%d%d",&m,&n);
long long ans = ;
if(n%==)
{
ans = n/*pow_m(m,n/)+n/*pow_m(m,n/+);
ans %= MOD;
}
else ans = n*pow_m(m,n/+);
//cout<<ans<<endl;
for(int i = ;i < n;i++)
{
ans += pow_m(m,gcd(i,n));
ans %= MOD;
//cout<<ans<<endl;
}
ans *= mod_reverse(*n,MOD);
ans%=MOD;
printf("Case #%d: %I64d\n",iCase,ans);
}
return ;
}
HDU 3923 Invoker(polya定理+逆元)的更多相关文章
- HDU 3923 Invoker(polya定理+乘法逆元(扩展欧几里德+费马小定理))
Invoker Time Limit : 2000/1000ms (Java/Other) Memory Limit : 122768/62768K (Java/Other) Total Subm ...
- HDU 3923 Invoker 【裸Polya 定理】
参考了http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 的模板 对于每一种染色,都有一个等价群,例如旋转, ...
- poj 1286 Necklace of Beads poj 2409 Let it Bead HDU 3923 Invoker <组合数学>
链接:http://poj.org/problem?id=1286 http://poj.org/problem?id=2409 #include <cstdio> #include &l ...
- HDU 3923 Invoker | 暑训Day1 C题填坑
暑训第一天,专题为组合数学与概率期望. 最近一个月都没有学习新的知识,上午听聚聚讲课头脑都是一片空白.加上长期没刷题,下午做练习题毫无感觉.到晚上总算理清了蓝书上的一些概念,跟着榜单做题.最后唯独剩下 ...
- [ACM] hdu 3923 Invoker (Poyla计数,高速幂运算,扩展欧几里得或费马小定理)
Invoker Problem Description On of Vance's favourite hero is Invoker, Kael. As many people knows Kael ...
- hdu 3923 Invoker
完全是套用polya模版…… ;}
- HDU 4633 Who's Aunt Zhang (Polya定理+快速幂)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4633 典型的Polya定理: 思路:根据Burnside引理,等价类个数等于所有的置换群中的不动点的个 ...
- hdu 1817 Necklace of Beads(Polya定理)
Necklace of Beads Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu 3547 (polya定理 + 小高精)
DIY CubeTime Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Sub ...
随机推荐
- mongodb 物理删除数据
刚开始用mongodb的时候,感觉很好用,速度很快,不过后面就遇到一个问题,数据物理内存一直增加,删除表也不管用. 然后网上找了各种办法,最后发现一个办法管用,就是物理删除存储数据. 操作如下: 1. ...
- EF5&MVC4 学习1、创建新的Contoso University Application,并创建Model Class 生成对应的database
参考:http://www.asp.net/mvc/tutorials/getting-started-with-ef-5-using-mvc-4/creating-an-entity-framewo ...
- Intellij IDEA13 创建多模块Maven项目
目标:构建一个类似于如下图所示的这种结构的Maven项目. 首先,需要选中“File”——>“New Project”如下图所示 选中“Maven”,设置项目名称与项目构建地址,点击“Next” ...
- Npoi Web 项目中(XSSFWorkbook) 导出出现无法访问已关闭的流的解决方法
原本在CS项目中用的好好的在BS项目中既然提示我导出出现无法访问已关闭的流的解决方法 比较郁闷经过研究 终于解决了先将方法发出来 让遇到此问题的筒子们以作参考 //新建类 重写Npoi流方法 publ ...
- PHP配置文件详解php.ini [转]
[PHP] ; PHP还是一个不断发展的工具,其功能还在不断地删减 ; 而php.ini的设置更改可以反映出相当的变化, ; 在使用新的PHP版本前,研究一下php.ini会有好处的 ;;;;;;;; ...
- 定时组件quartz系列<一>模拟定时组件小程序
一.核心概念 Quartz的原理不是很复杂,只要搞明白几个概念,然后知道如何去启动和关闭一个调度程序即可. 1.Job表示一个工作,要执行的具体内容.此接口中只有一个方法void execute(Jo ...
- log4j配置文件详细解释
web.xml中配置启动log4j的配置 <!-- webAppRootKey进行配置,这里主要是让log能将日志写到对应项目根目录下 --> <!-- 定义以后,在Web Cont ...
- CentOS安装tomcat
一.下载Tomcat 1..进入Tomcat官网:http://tomcat.apache.org/ 左侧选择相应的版本 点击Tomcat 6.0后 点击tar.gz下载apache-tomcat-6 ...
- Windows下PHP+Eclipse开发环境搭建 及错误解决(apache2.2服务无法启动 发生服务特定错误:1)
前言 Eclipse与php/apache的关系:Eclipse只是用来写代码的,如果想要在浏览器查看运行效果就要让php/apache的运行目录指向你的代码目录.Eclipse貌似不会自己和apac ...
- Android彩蛋效果,微信彩蛋效果
根据Android源码修改,具有微信彩蛋效果 主要代码 public static class Board extends FrameLayout { public static final bool ...