-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem023.java
More file actions
30 lines (30 loc) · 887 Bytes
/
Problem023.java
File metadata and controls
30 lines (30 loc) · 887 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
import java.util.ArrayList;
public class Problem23 {
public static void main(String[] args) {
ArrayList<Integer> abundants = new ArrayList<Integer>();
boolean[] abundBool = new boolean[28123];
for (int i = 1; i < 28123; i++) {
int sum = 0;
for (int j = 1; j < i; j++) {
if (i % j == 0) {
sum += j;
}
}
if (sum > i) {
abundBool[i] = true;
abundants.add(i);
}
}
int total = 0;
for (int i = 1; i < 28123; i++) {
boolean found = false;
for (int j : abundants) {
if (i - j >= 0 && abundBool[i - j]) {
found = true;
}
}
total += found ? 0 : i;
}
System.out.println(total);
}
}