OneCompiler

Factorial Prime Number

211

Write a program to print factorial prime number.

//FACTORIAL PRIME NUMBER : A factorial prime is a prime number that is one less or one more than a factorial (all factorials greater than 1 are even).
Example: 2, 3, 5, 7, 23, 719, 5039, 39916801, 479001599, 87178291199

import java.util.*;

public class PrimeFact
{
int num,sum;
PrimeFact()
{
num=0;
sum=0;
}
void accept()
{
Scanner sc = new Scanner(System.in);
num=sc.nextInt();
}
void greatestFacts()
{
int n=num;
for(int i=2;i<=n;i++)
{
if(n%i==0)
{
n/=i;
System.out.println(i);
sum+=i;
--i;
}
}
}
void print()
{
System.out.println("ORIGINAL : "+ num);
System.out.println("SUM : " + sum);
if(num==sum)
System.out.println(num+ " Is a FACTORIAL PRIME NUMBER");
else
System.out.println(num+ " Is not a FACTORIAL PRIME NUMBER ");
}
public static void main(String[]args)
{
PrimeFact ob = new PrimeFact();
ob.accept();
ob.greatestFacts();
ob.print();
}
}

TO FIND OUTPUT : CLICK >> https://onecompiler.com/java/3yduuts55