题解 | #小乐乐与欧几里得#

小乐乐与欧几里得

https://www.nowcoder.com/practice/da13e0cf321e4df9acd0fdf0a433cbb0

#include <stdio.h>

int main() {
    long m = 0;
    long n = 0;
    while(scanf("%d %d", &m, &n) == 2)
    {
        long l =0;
        long sum = 0;
        long mul = m*n;
        while((l = m%n) != 0)
        {
            m = n;
            n = l;
        }
        //最大公约数为n
        //最小公倍数为m/n
        sum = n + mul/n;
        printf("%ld\n", sum);
    }
    return 0;
}

全部评论

相关推荐

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