-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProblem_034.java
More file actions
41 lines (33 loc) · 800 Bytes
/
Problem_034.java
File metadata and controls
41 lines (33 loc) · 800 Bytes
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
package euler;
import java.util.ArrayList;
public class Problem_034 {
static int digitFactorialSum() {
ArrayList<Integer> curiousNums = new ArrayList<Integer>(30);
int sum = 0;
for(int i = 11; i < 50000; i ++) {
if(isCurious(i)) {
sum += i;
curiousNums.add(i);
}
}
// System.out.println(curiousNums.toString());
return sum;
}
private static boolean isCurious(int n) {
int sum = 0;
String num = Integer.toString(n);
if(n == 1 || n == 2) return false;
for(int i = 0; i < num.length(); i++) {
sum += factorial(Integer.parseInt(num.substring(i, i + 1)));
}
return sum == n;
}
private static long factorial(int n) {
long factorial = 1;
if(n == 0) return 1;
for(int i = n; i > 0; i--) {
factorial *= i;
}
return factorial;
}
}