求最小公倍数,先求最大公约数(辗转相除法)
#include <iostream>
#include <iostream>
using namespace std;
int gcd(int a,int b)
{
return (a%b==0)?b:gcd(b,a%b);
}
int lcm(int a,int b)
{
if (a<b) swap(a,b);
int ans=a*b/gcd(a,b);
return ans;
}
int main()
{
int a,b,c,ab,abc;
while (cin>>a>>b>>c)
{
ab=lcm(a,b);
abc=lcm(ab,c);
cout<<abc<<endl;
}
return 0;
}