Logo

Programming-Idioms

History of Idiom 75 > diff from v20 to v21

Edit summary for version 21 by Shoo:
New Erlang implementation by user [Shoo]

Version 20

2017-07-26, 00:43:44

Version 21

2018-12-28, 09:41:08

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
gcd(A,B) when A == 0; B == 0 -> 0;
gcd(A,B) when A == B -> A;
gcd(A,B) when A > B -> gcd(A-B, B);
gcd(A,B) -> gcd(A, B-A).

lcm(A,B) -> (A*B) div gcd(A, B).
Demo URL
https://ideone.com/DKvsYZ