Program for nth Fuss – Catalan Number | Java 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 Fuss - Catalan number in O ( n ) time ; Calculate value of 3 nCn ; return 3 nCn / ( 2 n + 1 ) ; Driver code
class GFG { static int binomialCoeff ( int n , int k ) { int res = 1 ; if ( k > n - k ) k = n - k ; for ( int i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } static int Fuss_catalan ( int n ) { int c = binomialCoeff ( 3 * n , n ) ; return c / ( 2 * n + 1 ) ; } public static void main ( String [ ] args ) { for ( int i = 0 ; i < 10 ; i ++ ) System . out . print ( Fuss_catalan ( i ) + " ▁ " ) ; } }