Settings | Sign in | Sign up

There are currently 3 posts.

【试题】核桃的数量(三个数的最小公倍数的求法)

Floor 1 巨大八爪鱼 3/13/16 18:23
#include <stdio.h>

//#define gcd3(a, b, c) gcd(gcd((a), (b)), (c))
#define lcm(a, b) ((a) * (b) / gcd((a), (b)))

int gcd(int a, int b)
{
    int r;
    do
    {
        r = a % b;
        a = b;
        b = r;
    } while (r != 0);
    return a;
}

int lcm3(int a, int b, int c)
{
    int d = lcm(a, b);
    return lcm(d, c);
}

int main(void)
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    printf("%d\n", lcm3(a, b, c));
    return 0;
}
Floor 2 巨大八爪鱼 3/13/16 18:23
提交时间  03-13 18:23   评测结果  正确  
得分  100  
CPU使用  0ms  
内存使用  1.601MB  
Floor 3 巨大八爪鱼 3/13/16 18:23
三个数的最小公倍数的求法:
int lcm3(int a, int b, int c)
{
    int d = lcm(a, b);
    return lcm(d, c);
}
先得到a与b的最小公倍数d,再得到d与c的最小公倍数就是最终结果。

Content converter:

Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.
©2010-2025 Purasbar Ver3.0 [Mobile] [Desktop]
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported license.