What is the most efficient way to calculate the least common multiple of two integers?
I just came up with this, but it definitely leaves something to be desired.
First of all, you have to find the greatest common divisor
for(int i=1; i<=a && i<=b; i++) { if (i % a == 0 && i % b == 0) { gcd = i; } }
After that, using the GCD you can easily find the least common multiple like this
lcm = a / gcd * b;