Hi everyone
I have to finish the following task:
Define LCM(N)as the Least common multiple of 1, 2, 3, ..., N. Find LCM(N) mod 10^8.
This is an example: LCM(27) = 13433200
My problem is that the function leastCommonMultiple(min, max) returns in some cases infinit. I've got so far already:
function LCM(N) {
return leastCommonMultiple(1, N) % Math.pow(10,8);
}
function leastCommonMultiple(min, max) {
function range(min, max) {
var arr = [];
for (var i = min; i <= max; i++) {
arr.push(i);
}
return arr;
}
function gcd(a, b) {
return !b ? a : gcd(b, a % b);
}
function lcm(a, b) {
return (a * b) / gcd(a, b);
}
var multiple = min;
range(min, max).forEach(function(n) {
multiple = lcm(multiple, n);
});
return multiple;
}
It would be coool if somebody has good skills in Maths an JS and can help me with this problem.
Greetings :)