-
Notifications
You must be signed in to change notification settings - Fork 0
/
e23.ceylon
44 lines (42 loc) · 1.08 KB
/
e23.ceylon
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
void euler23() {
Boolean isAbundant(Integer x) {
if (x < 12) {
return false;
}
variable Integer sum = 0;
Integer ceiling(Float f) {
if (f > f.integer.float) {
return f.integer + 1;
} else {
return f.integer;
}
}
Integer root = ceiling(x.float^0.5);
if (root * root == x) {
sum += root;
}
for (i in 2..(root -1)) {
if (x % i == 0) {
sum += i + (x / i);
}
}
return sum + 1 > x;
}
Integer[] abundants = [ for( i in 1..28123) if(isAbundant(i)) i];
variable Integer ans = 0;
for (i in 1..28123) {
variable Boolean wasSum = false;
for (a in abundants) {
if (a >= i) {
break;
} else if(isAbundant(i - a)) {
wasSum = true;
break;
}
}
if (!wasSum) {
ans += i;
}
}
print(ans);
}