text: Seeds ( Or Seed Roots ) of a number | PHP 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
code: < ? php $ MAX = 10000 ; $ prodDig = array_fill ( 0 , $ MAX , 0 ) ; function getDigitProduct ( $ x ) { global $ prodDig ; if ( $ x < 10 ) return $ x ; if ( $ prodDig [ $ x ] != 0 ) return $ prodDig [ $ x ] ; $ prod = ( int ) ( $ x % 10 ) * getDigitProduct ( ( int ) ( $ x / 10 ) ) ; $ prodDig [ $ x ] = $ prod ; return $ prod ; } function findSeed ( $ n ) { $ res = array ( ) ; for ( $ i = 1 ; $ i <= ( int ) ( $ n / 2 + 1 ) ; $ i ++ ) if ( $ i * getDigitProduct ( $ i ) == $ n ) array_push ( $ res , $ i ) ; if ( count ( $ res ) == 0 ) { echo " NO ▁ seed ▁ exists STRNEWLINE " ; return ; } for ( $ i = 0 ; $ i < count ( $ res ) ; $ i ++ ) echo $ res [ $ i ] . " ▁ " ; } $ n = 138 ; findSeed ( $ n ) ; ? >