Project Euler #5: Smallest multiple

  • + 0 comments

    function gcd(a, b) { while (b !== 0) { let temp = b; b = a % b; a = temp; } return a; }

    function lcm(a, b) { return (a * b) / gcd(a, b); }

    function smallestMultiple(n) { let result = 1; for (let i = 2; i <= n; i++) { result = lcm(result, i); } return result; }

    let n = parseInt(readLine()); console.log(smallestMultiple(n));