HDU 5187 zhx's contest(防爆__int64 )
来源:互联网 发布:国家打击网络棋牌赌博 编辑:程序博客网 时间:2024/04/30 01:17
Problem Description
As one of the most powerful brushes, zhx is required to give his juniorsn problems.
zhx thinks theith 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 modulep .
zhx thinks the
zhx defines a sequence
1:
2:
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
Input
Multiply test cases(less than 1000 ). Seek EOF as the end of the file.
For each case, there are two integersn and p separated by a space in a line. (1≤n,p≤1018 )
For each case, there are two integers
Output
For each test case, output a single line indicating the answer.
Sample Input
2 2333 5
Sample Output
21
思路:枚举 减 减 ; 减 加 ; 加 减 加 加 一共 2^(n-1)*2-2
1 2^(n-1) -2 2^(n-1) -2 1
// 2^n-2#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<stack>#include<vector>#include<set>#include<map>#define L(x) (x<<1)#define R(x) (x<<1|1)#define MID(x,y) ((x+y)>>1)typedef __int64 ll;#define fre(i,a,b) for(i = a; i <b; i++)#define mem(t, v) memset ((t) , v, sizeof(t))#define sf(n) scanf("%d", &n)#define sff(a,b) scanf("%d %d", &a, &b)#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)#define pf printf#define bug pf("Hi\n")using namespace std;#define INF 0x3f3f3f3f#define N 1001ll n,mod;ll fdd(ll x,ll m) //计算 x*m 居然不能直接算,否者会爆__int64 {ll ans=0;while(m){if(m&1) ans=(ans+x)%mod;x=(x+x)%mod;m>>=1;} return ans;}ll pow_(ll n,ll m){ ll ans=1; while(m) { if(m&1) ans=fdd(ans,n); //计算 ans*n n=fdd(n,n); //计算 n*n m>>=1; } return (ans-2+mod)%mod;}int main(){while(~scanf("%I64d%I64d",&n,&mod)){ ll ans=2; if(n==1) { ans=n%mod; pf("%I64d\n",ans); continue; } printf("%I64d\n",pow_(ans,n));} return 0;}
1 0
- HDU 5187 zhx's contest(防爆__int64 )
- Hdu 5187 zhx's contest(数学)
- HDU 5187 zhx's contest
- HDU - 5187 zhx's contest
- hdu 5187-zhx's contest
- HDU - 5187 - zhx's contest
- zhx's contest HDU
- zhx's contest (hdu 5187 快速幂+快速乘法)
- HDU - 5187 - zhx's contest (快速幂+快速乘)
- HDU 5187 zhx's contest(快速幂+快速乘法)
- HDU 5187 zhx's contest(组合数学)
- HDU 5187zhx's contest(快速幂乘法)
- hdu 5187 zhx's contest ( 数学+java)
- HDU 5187 zhx's contest(快速乘法)
- hdu 5186 zhx's submissions 5187 zhx's contest快速幂小优化
- HDU 5187-zhx's contest(快速乘法+快速幂取模)
- hdu 5187 zhx's contest(快速幂矩阵6)
- hdu 5187 zhx's contest 快速幂,快速乘
- handler机制详解
- HDU 3635 Dragon Balls(并查集--路径压缩拓展应用)
- 设计模式-简单工厂模式
- 我在网易的十年
- LeetCode --- 58. Length of Last Word
- HDU 5187 zhx's contest(防爆__int64 )
- hdoj 1017 A Mathematical Curiosity
- iOS 链接错误file was built for archive which is not the architecture being linked (i386)
- 【转载】Android在Java代码中实现margin(实现组件间间隔)
- 【javascript】对象绑定事件
- zhx's contest (hdu 5187 快速幂+快速乘法)
- 我希望看到什么样的简历
- 实例演示使用RDIFramework.NET 框架的工作流组件进行业务流程的定义—请假申请流程-Web
- LeetCode --- 59. Spiral Matrix II