HDU 5187 zhx's contest(防爆__int64 )

Problem Description
As one of the most powerful brushes, zhx is required to give his juniors
nHDU 5187 zhx's contest(防爆__int64 )
problems.

zhx thinks the iHDU 5187 zhx's contest(防爆__int64 )thHDU 5187 zhx's contest(防爆__int64 )HDU 5187 zhx's contest(防爆__int64 )
problem's difficulty is iHDU 5187 zhx's contest(防爆__int64 ).
He wants to arrange these problems in a beautiful way.

zhx defines a sequence {aHDU 5187 zhx's contest(防爆__int64 )iHDU 5187 zhx's contest(防爆__int64 )}HDU 5187 zhx's contest(防爆__int64 )
beautiful if there is an iHDU 5187 zhx's contest(防爆__int64 )
that matches two rules below:

1: aHDU 5187 zhx's contest(防爆__int64 )1HDU 5187 zhx's contest(防爆__int64 )..aHDU 5187 zhx's contest(防爆__int64 )iHDU 5187 zhx's contest(防爆__int64 )HDU 5187 zhx's contest(防爆__int64 )
are monotone decreasing or monotone increasing.

2: aHDU 5187 zhx's contest(防爆__int64 )iHDU 5187 zhx's contest(防爆__int64 )..aHDU 5187 zhx's contest(防爆__int64 )nHDU 5187 zhx's contest(防爆__int64 )HDU 5187 zhx's contest(防爆__int64 )
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
pHDU 5187 zhx's contest(防爆__int64 ).
 
Input
Multiply test cases(less than
1000HDU 5187 zhx's contest(防爆__int64 )).
Seek EOFHDU 5187 zhx's contest(防爆__int64 )
as the end of the file.

For each case, there are two integers nHDU 5187 zhx's contest(防爆__int64 )
and pHDU 5187 zhx's contest(防爆__int64 )
separated by a space in a line. (1≤n,p≤10HDU 5187 zhx's contest(防爆__int64 )18HDU 5187 zhx's contest(防爆__int64 )HDU 5187 zhx's contest(防爆__int64 ))
 
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's contest (高速幂+高速乘)


下一篇:hdu 5186(模拟)