Here you can find the source of lcm(BigInteger a, BigInteger b)
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
Parameter | Description |
---|---|
a | first number |
b | second number |
public static BigInteger lcm(BigInteger a, BigInteger b)
//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(); } }