Skip to content

Instantly share code, notes, and snippets.

@matinkaboli
Created October 9, 2017 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matinkaboli/632d8a108367a23cb045c15d8fc894fc to your computer and use it in GitHub Desktop.
Save matinkaboli/632d8a108367a23cb045c15d8fc894fc to your computer and use it in GitHub Desktop.
function checkDivisor(num) {
let sum = 0;
const check = Math.ceil(num / 2);
for (let i = 0; i <= check; i++) {
if (num % i === 0) {
sum += i;
}
}
return sum > num;
}
const abundants = [];
for (let i = 12; i < 28123; i++) {
if (checkDivisor(i)) {
abundants.push(i);
}
}
const nonAbundants = [];
for (let i = 0; i < 28123; i++) {
nonAbundants.push(i);
}
for (let i = 0, len = abundants.length; i < len; i++) {
for (let j = i; j < 28123; j++) {
if (abundants[i] + abundants[j] < 28123) {
nonAbundants[abundants[i] + abundants[j]] = 0;
} else {
break;
}
}
}
console.log(nonAbundants.reduce((a, b) => a + b));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment