Wedderburn – Etherington number | Java program to find N terms of the sequence ; Stores the Wedderburn Etherington numbers ; Function to return the nth Wedderburn Etherington numbers ; Base case ; If n is even n = 2 x ; get x ; a ( 2 x ) = a ( 1 ) a ( 2 x - 1 ) + a ( 2 ) a ( 2 x - 2 ) + ... + a ( x - 1 ) a ( x + 1 ) ; a ( x ) ( a ( x ) + 1 ) / 2 ; Store the ans ; Return the required answer ; If n is odd ; a ( 2 x - 1 ) = a ( 1 ) a ( 2 x - 2 ) + a ( 2 ) a ( 2 x - 3 ) + ... + a ( x - 1 ) a ( x ) , ; Store the ans ; Return the required answer ; Function to print first N Wedderburn Etherington numbers ; Store first 3 numbers ; Print N terms ; Driver code ; function call
import java . util . * ; class GFG { static HashMap < Integer , Integer > store = new HashMap < Integer , Integer > ( ) ; static int Wedderburn ( int n ) { if ( n <= 2 ) return store . get ( n ) ; else if ( n % 2 == 0 ) { int x = n / 2 , ans = 0 ; for ( int i = 1 ; i < x ; i ++ ) { ans += store . get ( i ) * store . get ( n - i ) ; } ans += ( store . get ( x ) * ( store . get ( x ) + 1 ) ) / 2 ; store . put ( n , ans ) ; return ans ; } else { int x = ( n + 1 ) / 2 , ans = 0 ; for ( int i = 1 ; i < x ; i ++ ) { ans += store . get ( i ) * store . get ( n - i ) ; } store . put ( n , ans ) ; return ans ; } } static void Wedderburn_Etherington ( int n ) { store . put ( 0 , 0 ) ; store . put ( 1 , 1 ) ; store . put ( 2 , 1 ) ; for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( Wedderburn ( i ) ) ; if ( i != n - 1 ) System . out . print ( " ▁ " ) ; } } public static void main ( String [ ] args ) { int n = 10 ; Wedderburn_Etherington ( n ) ; } }