Logo

Programming-Idioms

History of Idiom 75 > diff from v7 to v8

Edit summary for version 8 by :

Version 7

2015-08-22, 15:45:31

Version 8

2015-08-23, 19:50:46

Idiom #75 Compute LCM

Compute the least common multiple x of big integers a and b. Use an integer type able to handle huge numbers.

Idiom #75 Compute LCM

Compute the least common multiple x of big integers a and b. Use an integer type able to handle huge numbers.

Code
x = lcm(a, b);

int lcm(int a, int b) => (a * b) ~/ gcd(a, b);

int gcd(int a, int b) {
  while (b != 0) {
    var t = b;
    b = a % t;
    a = t;
  }
  return a;
}
Demo URL
https://dartpad.dartlang.org/9f49341cb3bbbcb6ce18