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;
}

最新文章

  1. LVS_DR模式构建配置
  2. iocp-socket 服务(借鉴别人的,根据自己的需要改的)未完待续
  3. PAT 解题报告 1010. Radix (25)
  4. IT公司100题-21-输入n和m,和等于m
  5. 小结JS中的OOP(上)
  6. 简约的返回顶部效果(jQuery)
  7. exp/imp 有很多弊端
  8. Qt for Android遇到的几个错误解决[Win7 + Qt5.6 +jdk 8u91]
  9. lucene 多字段查询-MultiFieldQueryParser
  10. 深究WeixinJSBridge未定义之因
  11. HTML5的常用新特性你必须知道
  12. How to configure ODBC DSN to access local DB2 for Windows
  13. Jmeter 测试工具
  14. 安装Python模块:pygame
  15. CodeForces - 946D Timetable (分组背包+思维)
  16. MyEclipse2017CI破解教程
  17. Word图片上传控件(WordPaster)更新-2.0.15版本
  18. C++ 学习笔记 变量和基本类型(一)
  19. 为mongodb数据库增加用户名密码权限
  20. Poj 题目分类

热门文章

  1. Mysql存储过程包括事务,且传入sql数据运行
  2. lpad&amp;amp;rpad
  3. 学习 shell —— 条件判断 if 的参数
  4. Oracle多表连接效率,性能优化
  5. Oracle Hint的用法
  6. 切换JDK版本quick
  7. BZOJ 3667 Pollard-rho &amp;Miller-Rabin
  8. Spring《五》集合的注入方式
  9. 远程桌面连接Windows Azure中的Ubuntu虚拟机
  10. python中set集合的使用