蓝桥杯 PREV-1 核桃的数量

试题 历届试题 核桃的数量

资源限制
时间限制:1.0s 内存限制:256.0MB

问题描述

小张是软件项目经理,他带领3个开发组。工期紧,今天都在加班呢。为鼓舞士气,小张打算给每个组发一袋核桃(据传言能补脑)。他的要求是:

  1. 各组的核桃数量必须相同

  2. 各组内必须能平分核桃(当然是不能打碎的)

  3. 尽量提供满足1,2条件的最小数量(节约闹革命嘛)

输入格式

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

输出格式

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

样例输入1

2 4 5

样例输出1

20

样例输入2

3 1 1

样例输出2

3

思路:

因为最后要让每一组一样,并且都能均分,那么也就是 x x % a = 0 , x a=0,x % b = 0 , x b=0,x % c = 0 c=0 x x 取最小就是 a , b , c a,b,c 的最小公倍数了,所以就是这三个的最小公倍数,所以我们先求出 a , b a,b 的公倍数,然后就可以算出总共的了。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return ;
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1:1;
    ret = (c == '-') ? 0:(c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return ;
}
inline void out(int x) {
    if (x > 9) out(x / 10);
    putchar(x % 10 + '0');
}
int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
int main() {
    int a, b, c;
    read(a), read(b), read(c);
    int gcab = gcd(a, b);
    int lcmab = a * b / gcab;
    int gcabc = gcd(lcmab, c);
    int lcmabc = lcmab * c / gcabc;
    out(lcmabc);
    return 0;
}

发布了463 篇原创文章 · 获赞 27 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/weixin_45031646/article/details/105490625