1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #include<bits/stdc++.h> #define int long long #define ull unsigned long long #define maxn 3005 #define put() putchar('\n') #define Tp template<typename T> #define Ts template<typename T,typename... Ar> using namespace std; Tp void read(T &x){ int f=1;x=0;char c=getchar(); while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();} while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();} x*=f; } namespace Debug{ Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;} Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);} #define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__) }using namespace Debug; #define fi first #define se second #define mk make_pair int n,mod; int ans; int s[maxn][maxn],c[maxn][maxn]; int power(int x,int y=mod-2,int p=mod) { int sum=1; while (y) { if (y&1) sum=sum*x%p; x=x*x%p;y>>=1; } return sum; } void add(int &x,int y) {x=(x+y)%mod;} signed main(void){ int i,j; read(n);read(mod); s[0][0]=1; for (i=0;i<=n+1;i++) { c[i][0]=1; for (j=1;j<=i;j++) { c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod; s[i][j]=(s[i-1][j-1]+s[i-1][j]*j)%mod; } } for (i=0;i<=n;i++) { int res=power(2,power(2,n-i,mod-1))*c[n][i]%mod; int sum=0,buf=1,tmp=power(2,n-i); for (j=0;j<=i;j++) { add(sum,s[i+1][j+1]*buf); buf=buf*tmp%mod; } res=res*sum%mod; if (i&1) add(ans,mod-res); else add(ans,res); } printf("%lld\n",ans); return 0; }
|