code:
#include <bits/stdc++.h> #define N 1000005 #define LL long long using namespace std; const LL mod=1000000007; void setIO(string s) { string in=s+".in"; string out=s+".out"; freopen(in.c_str(),"r",stdin); } int a[N]; LL fac[N],inv[N],f[N],g[N],poww[N]; LL qpow(LL x,LL y) { LL tmp=1ll; for(;y;y>>=1,x=x*x%mod) if(y&1) tmp=tmp*x%mod; return tmp; } LL Inv(LL x) { return qpow(x,mod-2); } LL C(int x,int y) { return fac[x]*inv[y]%mod*inv[x-y]%mod; } int main() { // setIO("input"); int i,j,n,k; fac[0]=inv[0]=poww[0]=1ll; scanf("%d%d",&n,&k); for(i=1;i<=n;++i) fac[i]=fac[i-1]*1ll*i%mod,inv[i]=Inv(fac[i]),poww[i]=poww[i-1]*2ll%(mod-1); for(i=0;i<=n;++i) f[i]=C(n,i)*qpow(2,poww[n-i])%mod; LL ans=0ll; for(i=k;i<=n;++i) (ans+=(qpow(-1,i-k)*C(i,k)%mod*f[i]%mod+mod)%mod)%=mod; printf("%lld\n",ans); return 0; }