Given a number K which represents the factorial of a number N, the task is to find the value of N.
Note: K < 1018
Input: K = 120
5! = 1 * 2 * 3 * 4 * 5 = 120
Input: K = 6
3! = 1 * 2 * 3 = 6
Approach: It is given that the value of N! is less than 1018. On observation we can see that this is true only for N <= 18. Therefore we can precompute values of factorials from 1 to 18 and store it in a Hash Table or Map. After precomputation, for every value of N!, the corresponding N is returned in constant time.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find the maximum possible value of the minimum value of modified array
- Find length of period in decimal value of 1/n
- Find minimum number of coins that make a given value
- Find the minimum value of m that satisfies ax + by = m and all values after m also satisfy
- Find minimum value to assign all array elements so that array product becomes greater
- Find minimum value of y for the given x values in Q queries from all the given set of lines
- Find value of (1^n + 2^n + 3^n + 4^n ) mod 5
- Find value of y mod (2 raised to power x)
- Find value of (n^1 + n^2 + n^3 + n^4) mod 5 for given n
- Find the value of N XOR'ed to itself K times
- Program to find greater value between a^n and b^n
- Find minimum number of Log value needed to calculate Log upto N
- Program to Find the value of cos(nΘ)
- Find the missing value from the given equation a + b = c
- Program to find the value of tan(nΘ)
- Program to find the value of sin(nΘ)
- Find the value of the function Y = (X^6 + X^2 + 9894845) % 971
- Find the value of max(f(x)) - min(f(x)) for a given F(x)
- Find maximum value of x such that n! % (k^x) = 0
- Find number from given list for which value of the function is closest to A
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.