问题描述
小张是软件项目经理,他带领3个开发组。工期紧,今天都在加班呢。为鼓舞士气,小张打算给每个组发一袋核桃(据传言能补脑)。他的要求是:
- 各组的核桃数量必须相同
- 各组内必须能平分核桃(当然是不能打碎的)
- 尽量提供满足1,2条件的最小数量(节约闹革命嘛)
输入格式
输入包含三个正整数a, b, c,表示每个组正在加班的人数,用空格分开(a,b,c<30)
输出格式
输出一个正整数,表示每袋核桃的数量。
样例输入1
2 4 5
样例输出1
20
样例输入2
3 1 1
样例输出2
3
题解:
首先要保证核桃数量是每个组人数的倍数,因为要能在组内平分,其次要保证分给每组的数量都相同,因此其实很容易想到就是三个组人数的最小公倍数。
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <deque>
#include <list>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <iterator>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double E = exp(1.0);
const int MOD = 1e9+7;
const int MAX = 1e5+5;
int a,b,c;
int gcd(int x,int y)
{
return x ? gcd(y%x,x) : y;
}
int lcm(int x,int y)
{
return x / gcd(x,y) * y;
}
int main()
{
/*
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
*/
cin >> a >> b >> c;
cout << lcm(lcm(a,b),c);
return 0;
}