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
  1. 2 233
  2. 3 5
 
Sample Output
  1. 2
  2. 1
  3.  

思路:枚举  减 减     ;  减   加      ;           加  减                      加      加             一共     2^(n-1)*2-2

1                  2^(n-1) -2              2^(n-1) -2                1

  1. // 2^n-2
  2.  
  3. #include<iostream>
  4. #include<cstdio>
  5. #include<cstring>
  6. #include<algorithm>
  7. #include<cmath>
  8. #include<queue>
  9. #include<stack>
  10. #include<vector>
  11. #include<set>
  12. #include<map>
  13.  
  14. #define L(x) (x<<1)
  15. #define R(x) (x<<1|1)
  16. #define MID(x,y) ((x+y)>>1)
  17.  
  18. typedef __int64 ll;
  19.  
  20. #define fre(i,a,b) for(i = a; i <b; i++)
  21. #define mem(t, v) memset ((t) , v, sizeof(t))
  22. #define sf(n) scanf("%d", &n)
  23. #define sff(a,b) scanf("%d %d", &a, &b)
  24. #define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
  25. #define pf printf
  26. #define bug pf("Hi\n")
  27.  
  28. using namespace std;
  29.  
  30. #define INF 0x3f3f3f3f
  31. #define N 1001
  32.  
  33. ll n,mod;
  34.  
  35. ll fdd(ll x,ll m) //计算 x*m 竟然不能直接算,否者会爆__int64
  36. {
  37. ll ans=0;
  38. while(m)
  39. {
  40. if(m&1) ans=(ans+x)%mod;
  41. x=(x+x)%mod;
  42. m>>=1;
  43. }
  44. return ans;
  45. }
  46.  
  47. ll pow_(ll n,ll m)
  48. {
  49. ll ans=1;
  50.  
  51. while(m)
  52. {
  53. if(m&1) ans=fdd(ans,n); //计算 ans*n
  54. n=fdd(n,n); //计算 n*n
  55. m>>=1;
  56. }
  57. return (ans-2+mod)%mod;
  58. }
  59.  
  60. int main()
  61. {
  62. while(~scanf("%I64d%I64d",&n,&mod))
  63. {
  64. ll ans=2;
  65. if(n==1)
  66. {
  67. ans=n%mod;
  68. pf("%I64d\n",ans);
  69. continue;
  70. }
  71. printf("%I64d\n",pow_(ans,n));
  72. }
  73.  
  74. return 0;
  75. }

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. Oracle学习(11):PLSQL程序设计

    PL/SQL程序结构及组成 什么是PL/SQL? •PL/SQL(Procedure Language/SQL) •PLSQL是Oracle对sql语言的过程化扩展 •指在SQL命令语言中添加了过程处 ...

  2. Linux多线程实践(一)线程基本概念和理论

    线程概念 在一个程序里的一个运行路线就叫做线程(thread).更准确的定义是:线程是"一个进程内部的控制序列/指令序列"; 对于每一个进程至少有一个运行线程; 进程  VS. 线 ...

  3. Android recovery UI实现分析

    Android recovery模式为何物? 关于这个问题, baidu上已经有无数的答案.不理解的朋友先补习一下. 从纯技术角度来讲, recovery和android本质上是两个独立的rootfs ...

  4. FFMpeg在Windows下搭建开发环境【转】

    本文转载自:http://blog.csdn.net/wootengxjj/article/details/51758621 版权声明:本文为博主原创文章,未经博主允许不得转载. FFmpeg 是一个 ...

  5. 移动端H5页面编辑器开发实战--原理结构篇

    很久前的写的文章了,转载下发到这里 原文地址: https://blog.csdn.net/tech_meizu/article/details/52288797

  6. Python笔记(三)

    # -*- coding:utf-8 -*- # 运算符 a,b=10,20 # 算术运算符:包括+.-.*./.%.**.//运算 print "********************1 ...

  7. Qt-信号和槽-多对多

    前言:介绍1对多,多对1以及多对多的案例. 一.1对多 演示内容:在QLineEdit输入时,同步label,text browser以及调试输出板同步显示. 1.1 新建工程 1.2 添加部件 拖入 ...

  8. Memcache使用场景

    session //php文件中 ini_set("session.save_handler", "memcache"); ini_set("sess ...

  9. B/S发布到服务器

    域名准备好了?准备好就开始跟我操作吧: 1:预先在项目的同目录下新建文件夹 Public 2:找到项目解决方案重新生成 3:项目右击 发布 到 Public 4: 登入服务器 打开 Internet管 ...

  10. rel= "noopener"

    rel= "noopener" <a href= "https://www.xiaogezi.cn/" target= "_blank" ...