Count digits in a factorial | Set 2 | Returns the number of digits present in n ! Since the result can be large long long is used as return type ; factorial of - ve number doesn 't exists ; base case ; Use Kamenetsky formula to calculate the number of digits ; Driver Code
function findDigits ( n ) { if ( n < 0 ) return 0 ; if ( n <= 1 ) return 1 ; let x = ( ( n * Math . log10 ( n / Math . E ) + Math . log10 ( 2 * Math . PI * n ) / 2.0 ) ) ; return Math . floor ( x ) + 1 ; } document . write ( findDigits ( 1 ) + " " ) ; document . write ( findDigits ( 50000000 ) + " " ) ; document . write ( findDigits ( 1000000000 ) + " " ) ; document . write ( findDigits ( 120 ) + " " ) ;