The least common multiple of two integers a and b is the smallest number that is both an integer multiple of a and also an integer multiple of b.
#include <iostream>
using namespace std;
static int gcd(int a, int b) {
if (a == 0) {
return b;
} else if (b == 0) {
return a;
} else if (a > b) {
return gcd(a - b, b);
} else {
return gcd(a, b - a);
}
}
static int lcm(int a,int b) {
return a * b / gcd( a, b);
}
int main() {
int a = 10, b = 6;
cout << "Least common multiple is: " << lcm(a, b) << endl;
return 0;
}
Least common multiple is: 30