hdu 5187(高精度快速幂)
zhx's contest
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1867    Accepted Submission(s): 596
zhx thinks the ith problem's difficulty is i. He wants to arrange these problems in a beautiful way.
zhx defines a sequence {ai} beautiful if there is an i that matches two rules below:
1: a1..ai are monotone decreasing or monotone increasing.
2: ai..an are monotone decreasing or monotone increasing.
He
wants you to tell him that how many permutations of problems are there
if the sequence of the problems' difficulty is beautiful.
zhx knows that the answer may be very huge, and you only need to tell him the answer module p.
For each case, there are two integers n and p separated by a space in a line. (1≤n,p≤1018)
3 5
1
In the first case, both sequence {1, 2} and {2, 1} are legal.
In the second case, sequence {1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 1} are legal, so the answer is 6 mod 5 = 1
#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long LL;
LL n,m; LL modular_multi(LL a, LL b, LL c) /// a * b % c
{
LL res, temp;
res = , temp = a % c;
while (b)
{
if (b & )
{
res += temp;
if (res >= c)
{
res -= c;
}
}
temp <<= ;
if (temp >= c)
{
temp -= c;
}
b >>= ;
}
return res;
}
LL modular_exp(LL a, LL b, LL c)
{
LL res, temp;
res = % c, temp = a % c;
while (b)
{
if (b & )
{
res = modular_multi(res, temp, c);
}
temp = modular_multi(temp, temp, c);
b >>= ;
}
return res;
}
int main()
{
while(scanf("%lld%lld",&n,&m)!=EOF)
{
LL ans = modular_exp(,n,m);
printf("%lld\n",(ans-+m)%m);
}
return ;
}
hdu 5187(高精度快速幂)的更多相关文章
- hdu 2462(欧拉定理+高精度快速幂模)
		The Luckiest number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ... 
- HDU 2855 (矩阵快速幂)
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2855 题目大意:求$S(n)=\sum_{k=0}^{n}C_{n}^{k}Fibonacci(k)$ ... 
- HDU 4471 矩阵快速幂 Homework
		题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4471 解题思路,矩阵快速幂····特殊点特殊处理····· 令h为计算某个数最多须知前h个数,于是写 ... 
- HDU - 1575——矩阵快速幂问题
		HDU - 1575 题目: A为一个方阵,则Tr A表示A的迹(就是主对角线上各项的和),现要求Tr(A^k)%9973. Input数据的第一行是一个T,表示有T组数据. 每组数据的第一行有n( ... 
- 洛谷试炼场-简单数学问题-P1045 麦森数-高精度快速幂
		洛谷试炼场-简单数学问题 B--P1045 麦森数 Description 形如2^P−1的素数称为麦森数,这时P一定也是个素数.但反过来不一定,即如果PP是个素数,2^P-1 不一定也是素数.到19 ... 
- hdu 1757 (矩阵快速幂) 一个简单的问题  一个简单的开始
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1757 题意不难理解,当x小于10的时候,数列f(x)=x,当x大于等于10的时候f(x) = a0 * ... 
- 随手练——HDU 5015 矩阵快速幂
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5015 看到这个限时,我就知道这题不简单~~矩阵快速幂,找递推关系 我们假设第一列为: 23 a1 a2 ... 
- HDU 3802 矩阵快速幂 化简递推式子 加一点点二次剩余知识
		求$G(a,b,n,p) = (a^{\frac {p-1}{2}}+1)(b^{\frac{p-1}{2}}+1)[(\sqrt{a} + \sqrt{b})^{2F_n} + (\sqrt{a} ... 
- 读入 并查集 gcd/exgcd 高精度 快速幂
		ios_base::sync_with_stdio(); cin.tie(); ], nxt[MAXM << ], Head[MAXN], ed = ; inline void added ... 
随机推荐
- win7 C/C++,QT安装环境总结
			1. 安装VMware,但是不能用,发现是权限问题,解决方式:使用管理员运行模式即可: 2. 安装win7 ultimate x64,找了半天找不到密钥,只要用激活软件,目前来说系统可用 3. 安装 ... 
- reactor工作模型
- 【Python】python之Character string
			1.python字符串 字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串,l Python不支持单字符类型,单字符也在Python也是作为一个字符串使用. ... 
- 解决hadoop 集群启动常见错误办法
			hadoop 集群常见错误解决办法 hadoop 集群常见错误解决办法: (一)启动Hadoop集群时易出现的错误: 1. 错误现象:Java.NET.NoRouteToHostException ... 
- 【转】C#获取当前路径7种方法
			webformvar s = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; //C盘 IIS路径 var s1 ... 
- 解决导出为Excel时文件名乱码的问题。
			以前代码:public static void htmlToExcel(HttpContext context, string title, string html, string fileCss = ... 
- C#语法糖大汇总【转发】
			首先需要声明的是“语法糖”这个词绝非贬义词,它可以给我带来方便,是一种便捷的写法,编译器会帮我们做转换:而且可以提高开发编码的效率,在性能上也不会带来损失.这让java开发人员羡慕不已,呵呵. 1. ... 
- [hihocoder 1050]求树的最长链
			题目链接:http://hihocoder.com/problemset/problem/1050 两种方法: 1. 两遍dfs,第一次随便找一个根,找到距离这个根最远的点,这个点必然是最长链的一端. ... 
- Substrings Sort string 基本操作
			You are given nn strings. Each string consists of lowercase English letters. Rearrange (reorder) the ... 
- hbase监控实现
			目前实现的监控概览 
