Problem Description
As one of the most powerful brushes, zhx is required to give his juniors
n
problems.

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.
 
Input
Multiply test cases(less than
1000).
Seek EOF
as the end of the file.

For each case, there are two integers n
and p
separated by a space in a line. (1≤n,p≤1018)
 
Output
For each test case, output a single line indicating the answer.
 
Sample Input
2 233
3 5
 
Sample Output
2
1

思路:枚举  减 减     ;  减   加      ;           加  减                      加      加             一共     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 1001 ll 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;
}

HDU 5187 zhx&#39;s contest(防爆__int64 )的更多相关文章

  1. HDU - 5187 - zhx&#39;s contest (高速幂+高速乘)

    zhx's contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  2. hdu 5187 zhx's contest [ 找规律 + 快速幂 + 快速乘法 || Java ]

    传送门 zhx's contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  3. HDU 5187 zhx's contest 快速幂,快速加

    题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5187 bc(中文): http://bestcoder.hdu.edu.cn/contes ...

  4. hdu 5187 zhx's contest (快速幂+快速乘)

    zhx's contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  5. HDU - 5187 zhx's contest(快速幂+快速乘法)

    作为史上最强的刷子之一,zhx的老师让他给学弟(mei)们出n道题.zhx认为第i道题的难度就是i.他想要让这些题目排列起来很漂亮. zhx认为一个漂亮的序列{ai}下列两个条件均需满足. 1:a1. ...

  6. hdu 5187 zhx's contest

    题目分析如果n=1,答案是1,否则答案是2n−2. 证明:ai肯定是最小的或者最大的.考虑另外的数,如果它们的位置定了的话,那么整个序列是唯一的. 那么ai是最小或者最大分别有2n−1种情况,而整个序 ...

  7. HDU - 5186 - zhx&#39;s submissions (精密塔尔苏斯)

    zhx's submissions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  8. HDU 5186 zhx&#39;s submissions (进制转换)

    Problem Description As one of the most powerful brushes, zhx submits a lot of code on many oj and mo ...

  9. HDU5187 zhx&#39;s contest(计数问题)

    主题链接: http://acm.hdu.edu.cn/showproblem.php?pid=5187 题意: 从1~n,有多少种排列 使得 a1~ai 满足单调递增或者单调递减. ai~an 满足 ...

随机推荐

  1. esql开发总结

    1 定义或者声明方法 int method(char *arg1,char* arg2...);   实现方法 int method(char *arg1,char* arg2...)     EXE ...

  2. mybatis使用generator自己主动生成代码时的类型转换

    使用mybatis的generator自己主动生成代码,可是oracle数据库中number(6,2)总是自己主动转成BigDecimal.我想要转成的是float类型 这样就写了一个类型转换器,须要 ...

  3. 【转】如何在Mac 终端升级ruby版本

    原文网址:https://segmentfault.com/a/1190000003784636 rvm是什么?为什么要安装rvm呢,因为rvm可以让你拥有多个版本的Ruby,并且可以在多个版本之间自 ...

  4. js最简单的-点击小图放大

    js最简单的-点击小图放大 标签(空格分隔): js <html> <body> <img class="imgview" src="{$v ...

  5. div position:fixed后,水平居中的问题

    .div{position:fixed;margin:auto;left:0; right:0; top:0; bottom:0;width:200px; height:150px;}

  6. CLR - 基础

    前言 好记性不如烂“笔头”系列... 目录 托管模块 JIT(just-in-time) 元数据 CLR 解析类型引用 托管模块 面向 CLR 的编译器在编译源文件时最终会编译成一个 PE(可移植执行 ...

  7. 清北集训Day1T3 LYK loves jumping(期望DP)

    题目描述 LYK在玩一个魔法游戏,叫做跳跃魔法. 有n个点,每个点有两个属性hi和ti,表示初始高度,和下降高度.也就是说,它初始时高度为hi,一旦LYK踩在这个点上,由于重力的影响,这个点的高度会下 ...

  8. 洛谷P4015 运输问题(费用流)

    题目描述 WW 公司有 mm 个仓库和 nn 个零售商店.第 ii 个仓库有 a_iai​ 个单位的货物:第 jj 个零售商店需要 b_jbj​ 个单位的货物. 货物供需平衡,即\sum\limits ...

  9. word-break属性和css换行显示

    这几天在做项目的时候,遇到了比较棘手的问题,便是在一个标签里边展示内容,如果说展示中文汉字,一点问题都没有,但是只要连续展示英文字母或者中文的标点符号(中间不带空格),那么所渲染的内容就不会换行,而是 ...

  10. 从Dinnr失败看产品市场可行性认知有哪些不足

    对所有互联网创始人来说,在实际创业之前「验证idea的市场可行性」是至关重要的事情,许多人会用访谈的方式询问潜在顾客的意见,本期的就已Dinnr为案例,当初用户访谈结果乐观,实际上线后却无人买单,创办 ...