Logo

Programming-Idioms

History of Idiom 75 > diff from v17 to v18

Edit summary for version 18 by programming-idioms.org:
[Go] +DemoURL

Version 17

2016-05-28, 23:54:30

Version 18

2017-02-07, 22:52:32

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 divides 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 divides a, by definition.

Chaining is permitted and idiomatic.

a, b, gcd, x have pointer type *big.Int.
Demo URL
https://play.golang.org/p/Un7geUbIZX