Number of ways of distributing N identical objects in R distinct groups | Function to return the value of ncr effectively ; Initialize the answer ; Divide simultaneously by i to avoid overflow ; Function to return the number of ways to distribute N identical objects in R distinct objects ; Driver code ; Function call
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 NoOfDistributions ( N , R ) : NEW_LINE INDENT return ncr ( N + R - 1 , R - 1 ) NEW_LINE DEDENT N = 4 NEW_LINE R = 3 NEW_LINE print ( NoOfDistributions ( N , R ) ) NEW_LINE