HDU 5187 zhx's contest(防爆__int64 )
n
problems.
zhx thinks the i
problem's difficulty is i
He wants to arrange these problems in a beautiful way.
zhx defines a sequence {a
beautiful if there is an i
that matches two rules below:
1: a
are monotone decreasing or monotone increasing.
2: a
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
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≤10
2 233
3 5
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's contest(防爆__int64 )的更多相关文章
- HDU - 5187 - zhx's contest (高速幂+高速乘)
zhx's contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- hdu 5187 zhx's contest [ 找规律 + 快速幂 + 快速乘法 || Java ]
传送门 zhx's contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- HDU 5187 zhx's contest 快速幂,快速加
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5187 bc(中文): http://bestcoder.hdu.edu.cn/contes ...
- hdu 5187 zhx's contest (快速幂+快速乘)
zhx's contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- HDU - 5187 zhx's contest(快速幂+快速乘法)
作为史上最强的刷子之一,zhx的老师让他给学弟(mei)们出n道题.zhx认为第i道题的难度就是i.他想要让这些题目排列起来很漂亮. zhx认为一个漂亮的序列{ai}下列两个条件均需满足. 1:a1. ...
- hdu 5187 zhx's contest
题目分析如果n=1,答案是1,否则答案是2n−2. 证明:ai肯定是最小的或者最大的.考虑另外的数,如果它们的位置定了的话,那么整个序列是唯一的. 那么ai是最小或者最大分别有2n−1种情况,而整个序 ...
- HDU - 5186 - zhx's submissions (精密塔尔苏斯)
zhx's submissions Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- HDU 5186 zhx's submissions (进制转换)
Problem Description As one of the most powerful brushes, zhx submits a lot of code on many oj and mo ...
- HDU5187 zhx's contest(计数问题)
主题链接: http://acm.hdu.edu.cn/showproblem.php?pid=5187 题意: 从1~n,有多少种排列 使得 a1~ai 满足单调递增或者单调递减. ai~an 满足 ...
随机推荐
- osEye.Net:离别是为了将来的重逢
这一时刻已经成为osEye历史..... 在热心网友的关怀和鼓励之下,osEye.net将继续运行着,感谢你们陪伴osEye一起走过.... 与你相知相恋已经有4个年头了,你的成长到成熟都让我历历在目 ...
- muduo总结
总结说的有的过大,算是对自己学习的一个总结.兴许会不断补充. 模型总结 muduo是基于非堵塞的IO和事件驱动的网络库. muduo的总体结构时one loop per thread+threadpo ...
- mongodb后台执行
默认的情况下,关闭shell,mongodb就停止执行了. 假设想在后台执行,启动时仅仅需加入 --fork函数就可以. 能够在日志路径后面加入--logappend.防止日志被删除. bin/mon ...
- 关于server和虚拟主机的差别
文章都是先由本人个人博客,孙占兴:www.teilim.com,先更新,随后CSDN博客才会更新.掌握第一动态请关注本人主站. 原文链接:http://www.teilim.com/guan-yu-y ...
- Android 对话框(Dialog) 及 自己定义Dialog
Activities提供了一种方便管理的创建.保存.回复的对话框机制,比如 onCreateDialog(int), onPrepareDialog(int, Dialog), showDialog( ...
- 希尔加密算法(湖南师范大学第六届大学生计算机程序设计竞赛)hnuoj11552
解密 Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 2, Accept ...
- 0x37 容斥原理与莫比乌斯函数
多重集的组合数公式得记下.cf451E就是这个的裸题 #include<cstdio> #include<iostream> #include<cstring> # ...
- Adding Kentico controls to the Visual Studio toolbox
https://docs.kentico.com/k10/references/kentico-controls https://docs.kentico.com/k10/references/ken ...
- IPK僵尸网络 看看其传播手法
转自:http://www.freebuf.com/vuls/154975.html 一.IPK僵尸网络概述 IPK僵尸家族是自2012年底就开始出现并长期持续活跃在境外的DDoS僵尸网络.2016年 ...
- Linux平台Oracle多个实例启动
如何在Linux系统中启动多个Oracle实例?相信很多Oracle的初学者都会碰到这一类问题,下面我简单介绍一下. 1.切换Oracle用户: # su oracle 2.切换到Oracle目录下: ...