AtCode ABC148 - C - Snack
标签
- 数学、最大公约数、最小公倍数
唯一了解完题意,几分钟做出来的题,不要觉得水平提高了,是这道题太水了,想明白了,分分钟搞定!
题目地址
C - Snack
- https://atcoder.jp/contests/abc148/tasks/abc148_c?lang=en
问题描述
Problem Statement
Takahashi is organizing a party.
At the party, each guest will receive one or more snack pieces.
Takahashi predicts that the number of guests at this party will be A or B.
Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted.
We assume that a piece cannot be divided and distributed to multiple guests.
Constraints
- 1 leq A, B leq 10^5
- A neq B
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
代码语言:javascript复制A B
Output
Print the minimum number of pieces that can be evenly distributed to the guests in both of the cases with A guests and B guests.
Sample Input 1
代码语言:javascript复制2 3
Sample Output 1
代码语言:javascript复制6
When we have six snack pieces, each guest can take three pieces if we have two guests, and each guest can take two if we have three guests.
Sample Input 2
代码语言:javascript复制123 456
Sample Output 2
代码语言:javascript复制18696
Sample Input 3
代码语言:javascript复制100000 99999
Sample Output 3
代码语言:javascript复制9999900000
题意
- 高桥想举办一次聚会
- 参加的人每个人都会分配1个以上的点心
- 求不管A个人或者B个人都可以等分配的点心个数的最小值
- 1个点心不能拆开分
思路
- 求最小公倍数
- 这道题也是我刷题以来做的最快的一道C级题,题目比较水
题解
小码匠
代码语言:javascript复制void coder_solution() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long a, b;
cin >> a >> b;
cout << a * b / __gcd(a, b);
}
官方题解
代码语言:javascript复制ll A, B;
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> A >> B;
cout << lcm(A, B) << endl;
}