forked from Annex5061/java-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHoax_No.java
88 lines (83 loc) · 2.06 KB
/
Hoax_No.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//similar to smith no but we have to take only unique prime factors
import java.util.Scanner;
import java.lang.Math;
class Hoax{
int num;
int a=0, b=0;
int [] li, li1;
public Hoax(int n){
num=n;
li=new int[num];
}
public int[] factors(){
int n=num;
for(int i = 2; i <= Math.sqrt(n); i ++){
while (n % i == 0) {
li[a]=i;
a++;
n /= i;
}
}
if(n>2){
li[a]=n;
}
li1=new int[li.length];
for(int i=0; i<li.length-1; i++){
if(li[i]!=li[i+1]){
li1[b]=li[i];
b++;
}
}
return li1;
}
public int sumDigits(){
int n=num, sum=0;
while(n!=0){
int rem=n%10;
sum+=rem;
n=n/10;
}
return sum;
}
public int sumFactors(int[] li){
int sum=0;
for(int i=0; i<li.length; i++){
if(li[i]!=0) {
if(li[i]>9){
while(li[i]!=0){
int rem=li[i]%10;
sum+=rem;
li[i]/=10;
}
}
else {
sum += li[i];
}
}
}
return sum;
}
}
public class Hoax_No {
public static void main(String[] args) {
int a;
Scanner sc=new Scanner(System.in);
a= sc.nextInt();
Hoax s=new Hoax(a);
// int[] li=s.factors();
// for(int i=0; i<li.length; i++){
// if(li[i]!=0){
// System.out.println(li[i]);
// }
// }
int sf=s.sumFactors(s.factors());
// System.out.println(sf);
int sd=s.sumDigits();
if(sf==sd){
System.out.println(a+" is a Hoax number.");
}
else{
System.out.println(a+" is not a Hoax number.");
}
}
}