1 から 20 までのすべての数字の lcm を見つける必要があり、このコードを思いつきました。効率は悪いですが、正解よりも2倍多い答えが出てきます。誰か教えてくれませんか?
//variable used to shut off the while loop.
divisable = false;
var i = 2;
//function to prove if the number is a lcm
var isDivisable = function(number){
for(var i = 2; i<=20; i++){
if(number%i !== 0){
divisable = false;
// added the break to shut down the function,
// as no other loops need to be counted
break;
}else{
divisable = true;
}
}
};
while(!divisable){
isDivisable(i);
i+=2;
}