Find N from the value of N ! | Map to precompute and store the factorials of the numbers ; Function to precompute factorial ; Calculating the factorial for each i and storing in a map ; Driver code
var m = { } ; function precompute ( ) { var fact = 1 ; for ( var i = 1 ; i <= 18 ; i ++ ) { fact = fact * i ; m [ fact ] = i ; } } precompute ( ) ; var K = 120 ; document . write ( m [ K ] + " " ) ; K = 6 ; document . write ( m [ K ] ) ;