Find the smallest number X such that X ! contains at least Y trailing zeros . | Function to count the number of factors P in X ! ; Function to find the smallest X such that X ! contains Y trailing zeros ; Driver code
function countFactor ( P , X ) { if ( X < P ) return 0 ; return ( parseInt ( X / P ) + countFactor ( P , parseInt ( X / P ) ) ) ; } function findSmallestX ( Y ) { let low = 0 , high = 5 * Y ; let N = 0 ; while ( low <= high ) { let mid = parseInt ( ( high + low ) / 2 ) ; if ( countFactor ( 5 , mid ) < Y ) { low = mid + 1 ; } else { N = mid ; high = mid - 1 ; } } return N ; } let Y = 10 ; document . write ( findSmallestX ( Y ) ) ;