[leetcode]求最大公约数和最小公倍数(gcd和lcm算法)
求最大公约数和最小公倍数
Coding : 使用C++的库
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int a, b;
cout << "cin a and b of gcd : ";
cin >> a >> b;
int res = __gcd(a, b);
cout << "The gcd of "<< a << "," << b << " " << "is : " << res << endl;
int c,d;
cout << "cin c and d of lcm : ";
cin >> c >> d;
res = (c * d) / __gcd(c, d);
cout << "The lcm of "<< c << "," << d << " " << "is : " << res << endl;
return 0;
}