2101-核桃的数量 ZCMU

Description

小张是软件项目经理,他带领3个开发组。工期紧,今天都在加班呢。为鼓舞士气,小张打算给每个组发一袋核桃(据传言能补脑)。他的要求是:
1. 各组的核桃数量必须相同
2. 各组内必须能平分核桃(当然是不能打碎的)
3. 尽量提供满足1,2条件的最小数量(节约闹革命嘛)

Input

输入包含三个正整数a, b, c,表示每个组正在加班的人数,用空格分开(a,b,c<30)

Output

输出一个正整数,表示每袋核桃的数量。

Sample Input

2 4 5

Sample Output

20

思路:针对第二、三个要求,可以想到就是求三个数的最小公倍数

代码:

#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
    if(a<b)
      swap(a,b);
    int temp;
    while(a%b!=0)
    {
        temp=a%b;
        a=b;
        b=temp;
    }
    return b;
}
int main()
{
    int a,b,c;
    while(~scanf("%d%d%d",&a,&b,&c))
    {
       int two=a*b/gcd(a,b);
       int three=two*c/gcd(two,c);
       printf("%d\n",three);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/zcmu_2024/article/details/81133267