#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
using namespace std;
int gcd(int n,int m)
{
return m==0 ? n:gcd(m,n%m);
}
int lcm(int n,int m)
{
if(n<m)
swap(n,m);
return n/gcd(n,m)*m;
}
main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
printf("%d\n",lcm(n,m));
}
return 0;
}
HDU1018 (最小公倍数)HDU1018 (最小公倍数)
最新推荐文章于 2022-03-04 17:30:06 发布
本文介绍了一个计算两个整数最小公倍数(LCM)的C++程序。通过使用辗转相除法求最大公约数(GCD),进而计算出最小公倍数。程序包括输入输出示例,展示了如何调用函数来获取结果。

299

被折叠的 条评论
为什么被折叠?



