Write a program to get the highest factor of a number, which in turn has exactly four factors. If there is a perfect square apart from 1 in the factors, then the smallest perfect square should be returned.
Input (Number) | Output (Number) |
---|---|
2697 | 899 (899 is a factor of 2697 and it has exactly four factors 1, 29, 31 and 899) |
206625 | 25 (25 is a factor of 206625 and it is a perfect square, although there are other factors which have exactly four factors, they will not be considered) |
1073 | 1073 (1073 is a factor of 1073 and it has exactly four factors 1, 29, 37 and 1073) |
class HighestFactorOfNumber
{ public static void main(String s[])
{
int inputNumber = 2697;
int factor = highestFactor(inputNumber);
System.out.println("The factor is " + factor);
}
public static int highestFactor(int input)
{
//Write a code here to get the number as per the requirements. If required, you can use isPerfectSquare, getFactors methods.
}
public static boolean isPerfectSquare(int number)
{
//Write a code here to check if the given number is a perfect square or not and return it.
}
public static int[] getFactors(int number)
{
//Write a code here to find the factors of a given number and return it.
}
}
Topic: Learn Arrays And Loops