2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
smallestMultiple(n: number) : number {
let i = n;
while (true) {
let isDivisible = true;
for (let j = 1; j <= n; j++) {
if (i % j !== 0) {
isDivisible = false;
break;
}
}
if (isDivisible) {
return i;
}
i++;
}
}
Thoughts:
This is a fun problem, I wonder if there's a lower complexity solution to this.