I am trying to find friendly numbers among the first 10000 numbers.
Friendly numbers means that the divisors of a number added are equal to the other and then they are friends.
In this code, equal numbers are not taken into account.
I have managed to find them and make a functional code but when I run it it takes 13min to find the 10000 numbers.
var num1;
var num2;
function divisor (x){
var suma = 0;
for(var k=1;k<= Math.floor(x/2) + 1; k++){
if(x%k ==0){
suma = suma + k;
}
}
return suma;
}
for(var a = 2; a<10000; a++ ){
num1 = divisor(a);
for(var b= a; b<10000; b++){
num2 = divisor(b);
if(num1 == b && num2 == a && a<b){
console.log(a + ' y ' + b + ' son amigos' + '\n');
}
}
}