zhx's contest
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
For each case, there are two integers n and p separated by a space in a line. ( 1≤n,p≤1018 )
2 233 3 5
2 1
#include <cstdio>
#include <iostream>
long long mod;
using namespace std;
int main()
{
long long n,p,ans;
long long jia(long long a,long long b) ;
long long mul(long long n,long long k);
while(cin>>n>>mod)
{
if(mod==1) cout<<0<<endl;
else if(n==1) cout<<1<<endl;
else
{
ans=mul(2,n)-2;
if(ans<0) ans+=mod;
cout<<ans<<endl;
}
}
}
long long chen(long long n,long long k)
{
long long ans=0;
while(k)
{
if(k%2==1) ans=ans%mod+n%mod;
n=(n%mod)+(n%mod);
k/=2;
}
return ans;
}
long long mul(long long n,long long k)
{
long long ans=1;
while(k)
{
if(k%2==1) ans=chen(ans,n)%mod;
n=chen((n%mod),(n%mod));
k/=2;
}
return ans;
}
今天刚做了这个题目,就感觉很奇怪,为什么我用C++交上去是超时,换成G++就是AC,虽然能AC就好了,但我经常碰到这种怪事,还是希望有人来教教我怎么处理这些环境问题,有人教才是最幸福的啊。
https://vjudge.NET/contest/147891#problem/D