-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathProblem_23.java
More file actions
34 lines (32 loc) · 699 Bytes
/
Problem_23.java
File metadata and controls
34 lines (32 loc) · 699 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
class Problem_23 {
public static void main(String[] args){
int sum = 0;
boolean[] abundant = new boolean[28124];
for(int i = 0; i < abundant.length; i++) {
abundant[i] = isAbundant(i);
}
for(int i = 1; i < abundant.length; i++) {
if(!isSumOfAbundant(abundant, i)) {
sum += i;
}
}
System.out.println(sum);
}
public static boolean isAbundant(int n) {
int sum = 0;
for(int i = 1; i < Math.floor(n / 2) + 1; i++){
if(n % i == 0) {
sum += i;
}
}
return sum > n;
}
public static boolean isSumOfAbundant(boolean[] abundant, int n) {
for(int i = 0; i < n; i++) {
if(abundant[i] && abundant[n - i]) {
return true;
}
}
return false;
}
}