以下是代码实现:
#include <iostream>
#include <vector>
using namespace std;
// 最大公约数:greatest common divisor
int gcd(int a, int b) {
return !b ? a : gcd(b, a % b);
}
// 最小公倍数:Least common divisor
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
int main() {
cout << "greatest common divisor(gcd) = " << gcd(15, 25) << endl;
cout << "Least common divisor(lcm) = " << lcm(15, 25) << endl;
return 0;
}
代码输出为:
greatest common divisor(gcd) = 5
Least common divisor(lcm) = 75
谢谢阅读