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
def countFactor ( P , X ) : NEW_LINE INDENT if ( X < P ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT return ( X // P + countFactor ( P , X // P ) ) ; NEW_LINE DEDENT def findSmallestX ( Y ) : NEW_LINE INDENT low = 0 ; NEW_LINE high = 5 * Y ; NEW_LINE N = 0 ; NEW_LINE while ( low <= high ) : NEW_LINE INDENT mid = ( high + low ) // 2 ; NEW_LINE if ( countFactor ( 5 , mid ) < Y ) : NEW_LINE INDENT low = mid + 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT N = mid ; NEW_LINE high = mid - 1 ; NEW_LINE DEDENT DEDENT return N ; NEW_LINE DEDENT Y = 10 ; NEW_LINE print ( findSmallestX ( Y ) ) ; NEW_LINE