Code:
public static void main(String[] args) {
int num;
double sqrtnum;
double dividedsqrtnum;
double f;
int x = 0;
float a;
int d;
float p;
int q;
Scanner input = new Scanner(System.in);
System.out.println("Enter the number 'N'");
num = input.nextInt();
if( (num % 3) != 0){
System.out.println( "The number you entered is a semi-prime");
sqrtnum = Math.sqrt(num);
dividedsqrtnum = sqrtnum / 18;
f = Math.ceil(dividedsqrtnum) ;
System.out.println("The value of f is " + f);
// Algebraic expressions
for (x=0; x <= f; x++){
while (d == 1 || x ==f){
a = (num - 1 - 18 * x);
d = findGCD(num,a);
if ( d == 1){
x = x++;
}
else{
q = d;
p = (a / q + 1);
System.out.println("The divisors of "+ num +" are "+ p +" and " + q +" do you want to test another number? Y or N " );
}
}
}
}
else{
System.out.println("The number is not a semi-prime");
}
}
private static int findGCD(float num,float a) {
//base case
return findGCD(a, num%a);
}
}
Output:
Execute and get the output.
More Java Programs: