Find N from the value of N ! | C # 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
using System ; using System . Collections . Generic ; class GFG { static Dictionary < int , int > m = new Dictionary < int , int > ( ) ; static void precompute ( ) { int fact = 1 ; for ( int i = 1 ; i <= 18 ; i ++ ) { fact = fact * i ; m . Add ( fact , i ) ; } } public static void Main ( String [ ] args ) { precompute ( ) ; int K = 120 ; Console . Write ( m [ K ] + " STRNEWLINE " ) ; K = 6 ; Console . Write ( m [ K ] + " STRNEWLINE " ) ; } }