You are viewing a single comment's thread. Return to all 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));
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #5: Smallest multiple
You are viewing a single comment's thread. Return to all 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));