You are viewing a single comment's thread. Return to all comments →
JS implementation of this solution:
function getTotalX(a, b) { return [...new Array(Math.floor(gcd(b) / lcm(a)))] .map((_, i) => lcm(a) * (i + 1)) .filter(a => gcd(b) % a === 0) .length; } function gcd2(a, b) { if (!b) return a; return gcd2(b, a % b); } function lcm2(a, b) { return a * b / gcd2(a, b); } function gcd(arr) { return arr.reduce(gcd2); } function lcm(arr) { return arr.reduce(lcm2); }
Seems like cookies are disabled on this browser, please enable them to open this website
Between Two Sets
You are viewing a single comment's thread. Return to all comments →
JS implementation of this solution: