Java BigInteger LCM lcm(BigInteger... nums)

Here you can find the source of lcm(BigInteger... nums)

Description

lcm

License

Apache License

Declaration

public static BigInteger lcm(BigInteger... nums) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.math.BigInteger;

import java.util.Arrays;

public class Main {
    public static BigInteger lcm(BigInteger... nums) {
        return lcm(Arrays.asList(nums));
    }/* w w  w  . j  av  a  2s . c o  m*/

    public static BigInteger lcm(Iterable<BigInteger> nums) {
        BigInteger ret = null;
        for (BigInteger num : nums) {
            if (ret == null) {
                ret = num;
            } else {
                ret = lcm(ret, num);
            }
        }
        return ret;
    }

    public static BigInteger lcm(BigInteger num1, BigInteger num2) {
        return num1.multiply(num2.divide(num1.gcd(num2)));
    }

    public static BigInteger gcd(Iterable<BigInteger> nums) {
        BigInteger ret = null;
        for (BigInteger num : nums) {
            if (ret == null) {
                ret = num;
            } else {
                ret = ret.gcd(num);
            }
        }
        return ret;
    }
}

Related

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