Total ways of selecting a group of X men from N men with or without including a particular man | Function to return the value of nCr ; Initialize the answer ; Divide simultaneously by i to avoid overflow ; Function to return the count of ways ; Driver code
def nCr ( n , r ) : NEW_LINE INDENT ans = 1 ; NEW_LINE for i in range ( 1 , r + 1 ) : NEW_LINE INDENT ans *= ( n - r + i ) ; NEW_LINE ans //= i ; NEW_LINE DEDENT return ans ; NEW_LINE DEDENT def total_ways ( N , X ) : NEW_LINE INDENT return ( nCr ( N - 1 , X - 1 ) + nCr ( N - 1 , X ) ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 5 ; X = 3 ; NEW_LINE print ( total_ways ( N , X ) ) ; NEW_LINE DEDENT