题解 | #求最小公倍数#
求最小公倍数
https://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; void async function () { // Write your code here while(line = await readline()){ let [a,b] = line.split(' '); if(a>b){ [a,b] = [b,a] } // 思路:从2往上循环,如果两个a b数除完i之后余数为0,则i为公约数,然后重置 a b 的值,并且将 i--,因为除完了2,可能还有个2的公约数 let arr = [] for(let i = 2;i<=a;i++){ if(a%i == 0 && b%i == 0){ arr.push(i) a = a/i b = b/i i--; } } arr.push(a,b) console.log(arr.reduce((pre,v)=>pre*=v,1)) } }()