-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheu23_1.java
76 lines (50 loc) · 1.26 KB
/
eu23_1.java
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.util.ArrayList;
public class eu23_1 {
public static void main(String[] args) {
int limit = 20160;
int sum=0;
int tempNum;
int listSize;
ArrayList<Integer> list = new ArrayList<Integer>();
ArrayList<Integer> sumList = new ArrayList<Integer>();
for (int i=0; i<limit; i++) {
if (isAbundant(i)) {
list.add(i);
}
}
listSize = list.size();
for (int i=0; i<listSize; i++) {
for (int j=i; j<listSize; j++) {
tempNum = list.get(i) + list.get(j);
if (tempNum < limit) {
sumList.add(tempNum);
}
}
}
for (int i=1; i<limit; i++) {
if (sumList.contains(i) == false) {
sum += i;
}
}
System.out.println(sum);
}
public static boolean isAbundant(int n) {
int sum=0;
int t=n;
for(int j=1;j<=Math.sqrt(n);j++)
{
if (n%j==0){
sum=sum+(n/j);
sum=sum+j;
}
}
sum=sum-n;
double h=(int)Math.sqrt(n)*(int)Math.sqrt(n);
if(h==n)
{
sum=sum-(int) Math.sqrt(n);
}
if (sum>n) { return true; }
else { return false; }
}
}