题解 | #求最小公倍数#

求最小公倍数

https://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3

#include <bits/types/struct_tm.h>
#include <cstddef>
#include <iostream>
using namespace std;

int main() {
    int a, b;
    while (cin >> a >> b) { // 注意 while 处理多个 case
        size_t tmax = a * b;
        int ans = tmax;
        for (int i = tmax;i >= a;i--) {
            if (i % a == 0 && i % b == 0) {
                ans = min(ans, i);
            }
        }
        cout << ans <<  endl;
    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务