Numbers whose factorials end with n zeros | Function to calculate trailing zeros ; binary search for first number with n trailing zeros ; Print all numbers after low with n trailing zeros . ; Print result ; Driver code
< ? php function trailingZeroes ( $ n ) { $ cnt = 0 ; while ( $ n > 0 ) { $ n = intval ( $ n / 5 ) ; $ cnt += $ n ; } return $ cnt ; } function binarySearch ( $ n ) { $ low = 0 ; while ( $ low < $ high ) { $ mid = intval ( ( $ low + $ high ) / 2 ) ; $ count = trailingZeroes ( $ mid ) ; if ( $ count < $ n ) $ low = $ mid + 1 ; else $ high = $ mid ; } $ result = array ( ) ; while ( trailingZeroes ( $ low ) == $ n ) { array_push ( $ result , $ low ) ; $ low ++ ; } for ( $ i = 0 ; $ i < sizeof ( $ result ) ; $ i ++ ) echo $ result [ $ i ] . " ▁ " ; } $ n = 2 ; binarySearch ( $ n ) ; ? >