-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path023.js
More file actions
28 lines (27 loc) · 732 Bytes
/
023.js
File metadata and controls
28 lines (27 loc) · 732 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
const { listProperDivisors } = require('./utils');
console.time('23');
const isAbundant = (n) => listProperDivisors(n).reduce((a, b) => a + b) > n;
const max = 28123;
const abundants = [];
for (let i = 2; i <= max; i += 1) {
if (isAbundant(i)) {
abundants.push(i);
}
}
const abundantsSums = new Set();
for (let j = 0; j < abundants.length; j += 1) {
for (let k = j; k < abundants.length; k += 1) {
const sum = abundants[j] + abundants[k];
if (sum <= max) {
abundantsSums.add(sum);
}
}
}
const notAbundantsSums = [];
for (let l = 2; l <= max; l += 1) {
if (!abundantsSums.has(l)) {
notAbundantsSums.push(l);
}
}
console.log(notAbundantsSums.reduce((a, b) => a + b) + 1);
console.timeEnd('23');