Logo

Programming-Idioms

History of Idiom 75 > diff from v2 to v3

Edit summary for version 3 by :

Version 2

2015-08-21, 13:12:45

Version 3

2015-08-21, 13:13:53

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.

Imports
import "math/big"
Imports
import "math/big"
Code
gcd.GCD(nil, nil, a, b)
x.Div(a, gcd).Mul(x, b)
Code
gcd.GCD(nil, nil, a, b)
x.Div(a, gcd).Mul(x, b)
Comments bubble
LCM is not in the standard library, but can be deduced from GCD.

gcd div a, by definition.

Chaining is permitted and idiomatic.

a, b, gcd_, x have pointer type *big.Int .
Comments bubble
LCM is not in the standard library, but can be deduced from GCD.

gcd div a, by definition.

Chaining is permitted and idiomatic.

a, b, gcd, x have pointer type *big.Int .