题解 | #求最小公倍数#
求最小公倍数
https://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3
最小公倍数等于两数乘积 除以 两数的最大公约数
求最大公约数(gcd)辗转相除法
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
function gcd(a, b) {
if(a % b === 0) return b
return gcd(b, a % b)
}
function lcm(a, b) {
return a * b / gcd(a, b)
}
void async function () {
while(line = await readline()){
line = line.split(' ').map(Number)
console.log(lcm(line[0], line[1]))
}
}()
查看1道真题和解析