Logo

Programming-Idioms

History of Idiom 75 > diff from v31 to v32

Edit summary for version 32 by Wiseguy:
[Java] Clarify context of usage

Version 31

2019-10-17, 03:24:59

Version 32

2019-10-17, 03:27:27

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 java.math.BigInteger;
Imports
import java.math.BigInteger;
Code
x = a.multiply(b).divide(a.gcd(b));
Code
BigInteger a = new BigInteger("123456789");
BigInteger b = new BigInteger("987654321");
BigInteger x = a.multiply(b).divide(a.gcd(b));