-
Notifications
You must be signed in to change notification settings - Fork 56
/
Smithnumber.java
72 lines (66 loc) · 1.28 KB
/
Smithnumber.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.util.*;
import java.util.Scanner;
class prog
{ int n;
public prog()
{
n=0;
}
public void input()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
n=sc.nextInt();
}
public int prime(int k)
{ int c=0;
for(int i=1;i<=k;i++)
{
if(k%i==0)
{
c++;
}
}
if(c==2)
return 1;
else
return 0;
}
public int sumprime(int p)
{ int s=0;
while(p>0)
{
int d=p%10;
s=s+d;
p/=10;
}
return s;
}
public void calc()
{ int f; int sum=0;
int l=sumprime(n);
for(int i=2;i<=n;i++)
{
if(n%i==0)
{
f=prime(i);
if(f==1)
{
sum=sum+sumprime(i);
}
}
}
if(sum==l)
{
System.out.println("YES IT IS SMITH NUMBER");
}
else
System.out.println("IT IS NOT SMITH NUMBER");
}
public static void main(String args[])
{
prog ob=new prog();
ob.input();
ob.calc();
}
}