Given a positive integer N, the task is to check if N is a Factorial prime or not. If it is a factorial prime then print YES else print NO.
Input: N = 23
23 is a prime number and one less than factorial of 4 (4! = 24).
11 is a prime number but can not be expressed as either n! + 1 or n! – 1.
Approach: In order for N to be factorial number, N must be a prime and either N – 1 or N + 1 should be the value of factorial of any number.
- If N is not prime then print No.
- Else set fact = 1 and starting from i = 1 update fact = fact * i, if fact = N – 1 or fact = N + 1 then print Yes.
- Repeat the above step until fact ≤ N + 1 and if the condition is not satisfied then print No in the end.
Below is the implementation of the above approach:
- Largest power of k in n! (factorial) where k may not be prime
- Quick ways to check for Prime and find next Prime in Java
- Check if a prime number can be expressed as sum of two Prime Numbers
- Check whether the sum of prime elements of the array is prime or not
- Find the last digit when factorial of A divides factorial of B
- Check n^2 - m^2 is prime or not
- Check if N is Strong Prime
- Check if two numbers are co-prime or not
- Check whether a number is circular prime or not
- Check if a number is a Pythagorean Prime or not
- Check if a number is Primorial Prime or not
- Check whether the given numbers are Cousin prime or not
- Check if a number is Quartan Prime or not
- Check a number for Permutable Prime
- Check whether the given number is Wagstaff prime or not
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.