题解 | #求最小公倍数#

求最小公倍数

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 tokens = line.split(" ");
        let a = tokens[0];
        let b = tokens[1];
        let mul = a*b;
        while (a % b !== 0) { // 辗转相除法求最大公约数
            let c = a % b;
            a = b;
            b = c;
        }
		// b为最大公约数
        console.log(mul/b); // 最小公倍数=两数的乘积/最大公约数
    }
})();

全部评论

相关推荐

AAA专业长城贴瓷砖刘大爷:这样的简历我会直接丢进垃圾桶,花里胡哨的
点赞 评论 收藏
分享
水墨不写bug:疑似没有上过大学
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务