A smith number is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of prime fa...

A smith number is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of prime factorization (excluding 1).
The first few such numbers are 4, 22, 27, 58, 85, 94, 121.....

Examples

``````666 Prime factors are 2, 3, 3 and 37
Sum of the digits are (6+6+6) = 18
Sum of the digits of the factors (2+3+3+(3+7) = 18
``````

Sample data:

``````Input 94 Output SMITH Number
Input 102 Output NOT SMITH Number
``````
``````import java.util.*;

class ISCprac2008Q1{
public static void main(String sr[])throws InputMismatchException{

Scanner sc=new Scanner(System.in);
System.out.println("Enter a number: ");
int n=sc.nextInt();

int p,q,i,sod=0,sopf=0,t;

p=q=n;

while(p>0){
sod+=p%10;
p/=10;
}

for(i=2;i<=q;i++){
if(q%i==0){
t=i;
while(t>0){
sopf+=t%10;
t/=10;
}
q=q/i;
i--;
}
}

if(sod==sopf)
System.out.println("Smith number");
else
System.out.println("Not Smith number");

}//eom
}//eoc
``````