Given a number, we need to find LCM of the factorial of the numbers and its neighbors. If the number is N, we need to find LCM of (N-1)!, N! and (N+1)!.Here N is always greater than or equal too 1
Input : N = 5 Output : 720 Explanation Here the given number is 5, its neighbors are 4 and 6. The factorial of these three numbers are 24, 120, and 720.so the LCM of 24, 120, 720 is 720. Input : N = 3 Output : 24 Explanation Here the given number is 3, its Neighbors are 2 and 4.the factorial of these three numbers are 2, 6, and 24. So the LCM of 2, 6 and 24 is 24.
Method 1(Simple). We first calculate the factorial of number and and the factorial of its neighbor then
find the LCM of these factorials numbers.
We can see that the LCM of (N-1)!, N! and (N+1)! is always (N-1)! * N! * (N+1)!
this can be written as (N-1)! * N*(N-1)! * (N+1)*N*(N-1)!
so the LCM become (N-1)! * N * (N+1)
which is (N+1)!
N = 5
We need to find the LCM of 4!, 5!and 6!
LCM of 4!, 5!and 6!
= 4! * 5! * 6!
= 4! * 5*4! * 6*5*4!
So we can say that LCM of the factorial of three consecutive numbers is always the factorial of the largest number.in this case (N+1)!.
- Find the last digit when factorial of A divides factorial of B
- Puzzle | Neighbors in a round table
- Fill array with 1's using minimum iterations of filling neighbors
- Double factorial
- Last non-zero digit of a factorial
- Check if N is a Factorial Prime
- First digit in factorial of a number
- Count digits in a factorial | Set 2
- Sum of divisors of factorial of a number
- Factorial of a large number
- Count digits in a factorial | Set 1
- Count Divisors of Factorial
- Check if N-factorial is divisible by X^Y
- Program for factorial of a number
- Find the next Factorial greater than N
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.