Java BigInteger LCM lcm(BigInteger a, BigInteger b)

Here you can find the source of lcm(BigInteger a, BigInteger b)

Description

Least common multiple.<br> http://en.wikipedia.org/wiki/Least_common_multiple<br> lcm( 6, 9 ) = 18<br> lcm( 4, 9 ) = 36<br> lcm( 0, 9 ) = 0<br> lcm( 0, 0 ) = 0

License

Open Source License

Parameter

Parameter Description
a first number
b second number

Return

least common multiple of a and b

Declaration

public static BigInteger lcm(BigInteger a, BigInteger b) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.math.BigInteger;

public class Main {
    /**//from   w  ww  .  j a v  a 2  s  . com
     * Least common multiple.<br>
     * http://en.wikipedia.org/wiki/Least_common_multiple<br>
     * lcm( 6, 9 ) = 18<br>
     * lcm( 4, 9 ) = 36<br>
     * lcm( 0, 9 ) = 0<br>
     * lcm( 0, 0 ) = 0
     * @param a first number
     * @param b second number
     * @return least common multiple of a and b
     */
    public static BigInteger lcm(BigInteger a, BigInteger b) {
        if (a.signum() == 0 || b.signum() == 0)
            return BigInteger.ZERO;
        return a.divide(a.gcd(b)).multiply(b).abs();
    }
}

Related

  1. lcm(BigInteger a, BigInteger b)
  2. lcm(BigInteger... nums)
  3. lcm(BigInteger... values)