Calculate ( n C r )
int nCr ( int n , int r ) { return ( factorial [ n ] * invmod ( ( factorial [ r ] * factorial [ n - r ] ) % mod ) ) % mod ; } int CountWays ( int n , int k ) { StoreFactorials ( n ) ;