The Least Common Multiple (LCM) or Lowest Common Multiple of two integers is the smallest integer that is divisible by both numbers. The method that is provided in this post uses the Greatest Common Divisor (GCD). This one line method calculates the LCM by leveraging the GCD, the code of the GCD method is provided in the GCD post. The reason we divide before we multiply is to avoid the arithmetic overflow when dealing with large numbers.
public static long Lcm(long a, long b)
{
return (a / Gcd(a, b)) * b;
}
Least Common Multiple (LCM) – C# Method