Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <sstream>
- #include <string>
- #include <vector>
- #include <queue>
- #include <set>
- #include <map>
- #include <cstdio>
- #include <cstdlib>
- #include <cctype>
- #include <cmath>
- #include <cstring>
- using namespace std;
- typedef unsigned long long LL;
- #define FOR(k,a,b) for(int k(a); k < (b); ++k)
- #define FORD(k,a,b) for(int k(a-1); k >= (b); --k)
- #define REP(k,a) for(int k=0; k < (a); ++k)
- #define ABS(a) ((a)>0?(a):-(a))
- const int mod=1e9+7;
- const int mSize=5002;
- char *ipos, *opos, InpFile[200000], OutFile[200000];
- inline int readInt()
- {
- while(*ipos <= 32) ++ipos;
- int x=0;
- char c;
- while( 1 )
- {
- c=*ipos++;
- if (c<=32) return x;
- x*=10;
- x+=c-'0';
- }
- }
- inline void writeInt(int a)
- {
- opos+=sprintf(opos,"%d\n",a);
- }
- inline void InitIO() {
- ipos = InpFile;
- opos = OutFile;
- fread_unlocked(InpFile,200000,1,stdin);
- }
- inline void FlushIO() {
- fwrite_unlocked(OutFile,opos-OutFile,1,stdout);
- }
- int inverse(int a)
- {
- int n=mod-2;
- LL tmp=a,res=1;
- while(n)
- {
- if(n&1)
- res*=tmp;
- res%=mod;
- n>>=1;
- tmp*=tmp;
- tmp%=mod;
- }
- return res;
- }
- int main()
- {
- int inv[mSize],fact[mSize];
- fact[0]=1;
- inv[0]=1;
- FOR(i,1,mSize)
- {
- fact[i]=(fact[i-1]*(LL)i)%mod;
- inv[i]=inverse(fact[i]);
- }
- InitIO();
- int N,K,K1,K2;
- LL res=0;
- while(true)
- {
- /*scanf("%d %d",&N,&K);*/
- N=readInt();
- K=readInt();
- if(N==0 && K==0)
- break;
- if(N==1 || K>2*N-3)
- {
- //because k positive
- writeInt(0);
- continue;
- }
- --K;
- K1=K/2;
- K2=(K+1)/2;
- res=2LL*fact[N-2]*inv[K1];
- res%=mod;
- res*=inv[N-2-K1];
- res%=mod;
- res*=fact[N-2];
- res%=mod;
- res*=inv[K2];
- res%=mod;
- res*=inv[N-2-K2];
- res%=mod;
- writeInt(res);
- }
- FlushIO();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment