Example usage for org.apache.commons.math.util MathUtils lcm

List of usage examples for org.apache.commons.math.util MathUtils lcm

Introduction

In this page you can find the example usage for org.apache.commons.math.util MathUtils lcm.

Prototype

public static long lcm(long a, long b) 

Source Link

Document

Returns the least common multiple of the absolute value of two numbers, using the formula lcm(a,b) = (a / gcd(a,b)) * b.

Usage

From source file:org.netxilia.functions.MathFunctions.java

/**
 * Returns the least common multiple of one or more integers. Integer_1, integer_2,... integer_30 are integers whose
 * lowest common multiple is to be calculated.
 * /*from w w  w  . ja  v  a2s  . c  om*/
 * @param values
 * @return
 */
public long LCM(Iterator<Long> values) {
    if (!values.hasNext()) {
        return 1;
    }
    long result = values.next();
    while (values.hasNext()) {
        result = MathUtils.lcm(result, values.next());
    }
    return result;
}