
write a proggram to accept a number and check whether the sum of prime factors of a number is a prime number or not

import java.util.*;
class PrimeFactors {
static boolean isPrime(long number) {
boolean isPrime = false;
int i = (int) Math.ceil(Math.sqrt(number));
while (i > 1) {
if ((number != i) && (number % i == 0)) {
isPrime = false;
break;
} else if (!isPrime)
isPrime = true;
--i;
}
return isPrime;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
long n = input.nextLong();
long sum=0;
System.out.print("Sum of Prime Factors of " + n + " is: ");
for (long i = 2; i <= n / i; i++) {
while (n % i == 0) {
sum+=i;
n = n / i;
}
}
if (n > 1){
sum=sum+n;
}
else {
sum=sum+0;
}
System.out.print(sum);
System.out.println();
if(isPrime(sum)){
System.out.println("Sum of prime factors of a number is a prime number");
}
else{
System.out.println("Not Prime!");
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.