Given a number N (≤ 1018), the task is to find the next factorial number greater than N.
Input: N = 24
As 4! = 24. So the next number which factorial and greater than 24 is 5!, which is 120
Input: N = 150
As 5! = 120. So the next number which factorial and greater than 150 is 6!, which is 720.
- Precompute the factorial of all number upto 20 in an array as 20! > 1018.
- Traverse the factorial array and find the value which is just greater than N as the required next factorial number.
Below is the implementation of 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 last digit when factorial of A divides factorial of B
- Smallest subarray of size greater than K with sum greater than a given value
- Find the Next perfect square greater than a given number
- Next greater number than N with exactly one bit different in binary representation of N
- Next greater Number than N with the same quantity of digits A and B
- Elements greater than the previous and next element in an Array
- Count of Array elements greater than all elements on its left and next K elements on its right
- Find all factorial numbers less than or equal to n
- Find next greater number with same set of digits
- Find next greater element with no consecutive 1 in it's binary representation
- Largest number with maximum trailing nines which is less than N and greater than N-D
- Largest number less than N with digit sum greater than the digit sum of N
- Highest and Smallest power of K less than and greater than equal to N respectively
- Find K such that changing all elements of the Array greater than K to K will make array sum N
- Find the minimum permutation of A greater than B
- Find a number K such that exactly K array elements are greater than or equal to K
- Find the first natural number whose factorial is divisible by x
- Find sum of digits in factorial of a number
- Find maximum power of a number that divides a factorial
- Find GCD of factorial of elements of given array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.