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
- Check whether factorial of N is divisible by sum of first N natural numbers
- Check if factorial of N is divisible by the sum of squares of first N natural numbers
- Find the last digit when factorial of A divides factorial of B
- Check n^2 - m^2 is prime or not
- Check if two numbers are co-prime or not
- Check if N is Strong Prime
- Check if a number is Full Prime
- Check a number for Permutable Prime
- Check if a number is Primorial Prime or not
- Check if a number is a Pythagorean Prime or not
- Check if the given string is vowel prime
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.