No, the nest is not causing me problems. I am getting less than 2 seconds with 28123. The problem is that I am getting a high sum of integers and I do not understand the reason why.
I made it a little faster with the abundant number feature that indicates every number after 20161 is abundant.
But it is not enough to pass the tests because it is too slow yet.
Do you have any suggestions?
let divisorsOfAnumber=0;
let number=1;
let abudantNumber=0;
let upperBoundLimit=20161;
let arrayOfAbundantNumbers=[];
let iteration = 1;
let arrayOfIntegerNumbers = [];
let sumOfAllNumbers = 0;
let arrayOfTwoAbundantSum = [];
while(number<=upperBoundLimit){
for(let i = 0;i<number;i++){
if(number%i==0){
divisorsOfAnumber= divisorsOfAnumber + i;
};
};
if(divisorsOfAnumber>number){
abudantNumber=number;
arrayOfAbundantNumbers.push(abudantNumber);
//console.log("The number "+abudantNumber+" is an abundant number");
};
number = number + 1;
divisorsOfAnumber = 0;
};
for(let i = 0;i<arrayOfAbundantNumbers.length;i++){
for(let j = 0;j<arrayOfAbundantNumbers.length;j++){
arrayOfTwoAbundantSum.push(arrayOfAbundantNumbers[i]+arrayOfAbundantNumbers[j]);
};
};
//console.log(arrayOfTwoAbundantSum);
for(let i = 1;i<=upperBoundLimit;i++){
arrayOfIntegerNumbers.push(i);
};
//console.log(arrayOfIntegerNumbers,arrayOfAbundantNumbers);
let res = arrayOfIntegerNumbers.filter((e) => !arrayOfTwoAbundantSum.includes(e))
//console.log(res);
for(let i = 0;i<res.length;i++){
sumOfAllNumbers = sumOfAllNumbers + res[i];
};
console.log(sumOfAllNumbers);