-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem092.java
More file actions
33 lines (33 loc) · 828 Bytes
/
Problem092.java
File metadata and controls
33 lines (33 loc) · 828 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
public class Problem092 {
private static int[] ends;
private static boolean is89(int i) {
if (ends[i] == 89) {
return true;
} else if (ends[i] == 1) {
return false;
}
int sum = 0;
for (String s : String.valueOf(i).split("")) {
sum += Math.pow(Integer.parseInt(s), 2);
}
if (is89(sum)) {
ends[i] = 89;
return true;
}
ends[i] = 1;
return false;
}
public static void main(String[] args) {
ends = new int[10000000];
ends[0] = 1;
ends[1] = 1;
ends[89] = 89;
int total = 0;
for (int i = 1; i < 10000000; i++) {
if (is89(i)) {
total++;
}
}
System.out.println(total);
}
}