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 ...
随机推荐
- 运行时报错 ADB server didn’t ACK
查看进程中所有和ADB有关的进程,全都结束了,包括什么豌豆荚之类的(大多数情况是占用端口),之后重新启动Eclipse.
- tc srm 636 div2 500
100的数据直接暴力就行,想多了... ac的代码: #include <iostream> #include <cstdio> #include <cstring> ...
- hdu1050(贪心)
囧 . 想了好久,一开始想的是一个连通图怎样用黑白两色染色,想了各种算法发现都不好做,然后灵机一动这不是网路流吗,然后想怎么建图,如果转换成网络流这题就好做了,建图加个二分应该就可以解决了,最后又发现 ...
- core--线程调度
线程的调度和我们用人是同一个道理,假如我们是公司的CEO,你的手下有7名大将,10名美女,100000名普通员工,现在你的任务是在1年内情切慰问完所有的员工.你将如何安排这个行程?先从那些人开始?从哪 ...
- NuGet的安装;
下载完毕安装需要重启一下VS 然后我们去NuGet里面安装我们要的客户端 搜索 CouchbaseNetClient 引用之后,编译项目,查看到已引用的dll文件
- maven打包无法打包mybatis及系统配置文件问题
<resources> <!-- mybatis映射文件 --> <resource> <directory>src/main/java/com/bsh ...
- POJ 2084 Game of Connections
卡特兰数. #include<stdio.h> #include<string.h> ; ; void mul(__int64 a[],int len,int b) { int ...
- fmri的图像数据在matlab中显示,利用imagesc工具进行显示,自带数据集-by 西南大学xulei教授
这里包含了这样一个数据集:slice_data.mat. 这个数据集中包含的mri数据是:64*64*25.共有25个slice.每个slice的分辨率是64*64. 程序非常简短: load sli ...
- 每天一个Linux命令(7): cp
cp命令 该命令的功能是将给出的文件或目录拷贝到另一文件或目录中,同MSDOS下的copy命令一样,功能十分强大. 语法: cp [选项] 源文件或目录 目标文件或目录 ...
- .htaccess 文件的使用
用于服务器对文件夹的控制 官方解释为 :分布式配置文件 ,提供了针对目录改变配置的方法; 项目可以有多个这样的配置文件,子目录文件会覆盖父目录的配置 在apache(这里泛指服务器)中,/conf/v ...