-
Notifications
You must be signed in to change notification settings - Fork 4
/
p023.java
76 lines (59 loc) · 1.23 KB
/
p023.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
/**
*
* @author gouravrusiya
*
*/
public class p023 {
public static void main(String[] args) {
// TODO Auto-generated method stub
long startTime = System.currentTimeMillis();
int sumAll = 0;
//long nonAbundantSum = 0L;
int [] sumAbun = new int[28123];
int k = 0;
sumAll = ((20161)*(20162))/2;
//System.out.println(sumAll);
for(int i=12;i<20161;i++){
long sumDivisors = properDivisors(i);
if(sumDivisors>i){
sumAbun[k] = i;
//System.out.println(sumAbun[k]);
k++;
}
}
//System.out.println(k);
k--;
int flag = 0;
for(int i=12;i<20161;){
flag = 0;
for(int j=0;j<(k-1);j++){
for(int x=0;x<k;x++){
int y = sumAbun[j] + sumAbun[x];
if(y==i){
//System.out.println(i);
sumAll -= i;
//System.out.println("sum = "+sumAll);
flag = 1;
break;
}
}
if(flag==1)
break;
}
i++;
}
System.out.println(sumAll);
long endTime = System.currentTimeMillis();
System.out.println("Took "+(endTime - startTime) + " ms");
}
static long properDivisors(long i){
long sum = 0;
for(long j=1L;j<i;j++){
if((i%j)==0L){
//System.out.println(j);
sum += j;
}
}
return sum;
}
}