Program for nth Fuss – Catalan Number | Returns value of Binomial Coefficient C ( n , k ) ; Since C ( n , k ) = C ( n , n - k ) ; Calculate value of [ n * ( n - 1 ) * -- - * ( n - k + 1 ) ] / [ k * ( k - 1 ) * -- - * 1 ] ; A Binomial coefficient based function to find nth FussCatalan number in O ( n ) time ; Calculate value of 3 nCn ; return 3 nCn / ( 2 n + 1 ) ; Driver code
def binomialCoeff ( n , k ) : NEW_LINE INDENT res = 1 ; NEW_LINE if ( k > n - k ) : NEW_LINE INDENT k = n - k ; NEW_LINE DEDENT for i in range ( k ) : NEW_LINE INDENT res *= ( n - i ) ; NEW_LINE res //= ( i + 1 ) ; NEW_LINE DEDENT return res ; NEW_LINE DEDENT def Fuss_catalan ( n ) : NEW_LINE INDENT c = binomialCoeff ( 3 * n , n ) ; NEW_LINE return c // ( 2 * n + 1 ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT for i in range ( 10 ) : NEW_LINE INDENT print ( Fuss_catalan ( i ) , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT