-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq23.java
More file actions
44 lines (35 loc) · 807 Bytes
/
q23.java
File metadata and controls
44 lines (35 loc) · 807 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
42
43
44
import java.util.*;
public class q23 {
public static void main(String[] args){
// TODO Auto-generated method stub
boolean[] flag;
flag = new boolean[28123];
ArrayList<Integer> a = new ArrayList<Integer>();
for(int i = 1; i < 28123; ++i){
if(checkAbundance(i)){
for(int j = 0; j < a.size(); ++j){
if(a.get(j) + i >= 28123) continue;
flag[a.get(j) + i] = true;
}
a.add(i);
if( i < 28123 / 2) flag[2 * i] = true;
}
}
long result = 0;
for(int i = 0; i < 28123; ++i){
if(!flag[i]) result += i;
}
System.out.println(result);
}
public static int sumOfDivs(int x){
int sum = 0;
for(int i = 1; i < x; ++i){
if( x % i == 0)
sum += i;
}
return sum;
}
public static boolean checkAbundance(int x){
return sumOfDivs(x) > x;
}
}