版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sunlanchang/article/details/86296723
Description
给定两个正整数,计算这两个数的最小公倍数。
Input
输入包含多组测试数据,每组只有一行,包括两个不大于1000的正整数.
Output
对于每个测试用例,给出这两个数的最小公倍数,每个实例输出一行。
Sample Input
10 14
Sample Output
70
Solution
板题。两数字相乘再除以最大公约数就是最小公倍数。
#include <iostream>
#include <cstdio>
using namespace std;
int gcd(int a, int b)
{
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int main()
{
// freopen("in.txt", "r", stdin);
int a, b;
while (~scanf("%d%d", &a, &b))
{
printf("%d\n", a * b / gcd(a, b));
}
return 0;
}