Seeds ( Or Seed Roots ) of a number | Javascript program to find Seed of a number ; Stores product of digits of x in prodDig [ x ] ; If x has single digit ; If digit product is already computed ; If digit product is not computed before . ; Prints all seeds of n ; Find all seeds using prodDig ; If there was no seed ; Print seeds ; Driver code
var MAX = 10000 ; var prodDig = Array . from ( { length : MAX } , ( _ , i ) => 0 ) ; function getDigitProduct ( x ) { if ( x < 10 ) return x ; if ( prodDig [ x ] != 0 ) return prodDig [ x ] ; var prod = ( x % 10 ) * getDigitProduct ( parseInt ( x / 10 ) ) ; return ( prodDig [ x ] = prod ) ; } function findSeed ( n ) { var res = [ ] ; for ( var i = 1 ; i <= parseInt ( n / 2 ) ; i ++ ) if ( i * getDigitProduct ( i ) == n ) res . push ( i ) ; if ( res . length == 0 ) { document . write ( " " ) ; return ; } for ( i = 0 ; i < res . length ; i ++ ) document . write ( res [ i ] + " " ) ; } var n = 138 ; findSeed ( n ) ;