import java.io.*;
class Sphenic
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("N = ");
int n = Math.abs(Integer.parseInt(br.readLine()));
int a[] = {1, 1, 1};
int prime = 2;
int num = n;
int index = 0;
outer:
for(index = 0; index < 3;)
{
while(num % prime == 0)
{
a[index++] = prime;
num /= prime;
if(index == 3)
break;
if(num == 1)
break outer;
}
prime++;
if(prime > n)
break;
}
System.out.println("Factors: " + a[0] + ", " + a[1] + ", " + a[2]);
int product = a[0] * a[1] * a[2];
if(product == n)
{
if(a[0] != a[1] && a[1] != a[2] && a[2] != a[0])
{
if(a[0] > 1 && a[1] > 1 && a[2] > 1)
System.out.println(n + " is a sphenic number.");
else
System.out.println(n + " is not a sphenic number.");
}
else
System.out.println(n + " is not a sphenic number.");
}
else
System.out.println(n + " is not a sphenic number.");
}
}
No comments:
Post a Comment
any problem in any program comment:-