Find N from the value of N ! | Java program to find a number such that the factorial of that number is given ; 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 ; Precomputing the factorials
import java . util . * ; class GFG { static Map < Integer , Integer > m = new HashMap < Integer , Integer > ( ) ; static void precompute ( ) { int fact = 1 ; for ( int i = 1 ; i <= 18 ; i ++ ) { fact = fact * i ; m . put ( fact , i ) ; } } public static void main ( String [ ] args ) { precompute ( ) ; int K = 120 ; System . out . print ( m . get ( K ) + "NEW_LINE"); K = 6 ; System . out . print ( m . get ( K ) + "NEW_LINE"); } }