Java lcm lcm(long a, long b)

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

Description

lcm

License

Open Source License

Declaration

private static long lcm(long a, long b) 

Method Source Code

//package com.java2s;
/** Copyright (C) 2015 //from  www  .j ava2 s.  co m
 * @author Mitra Ansariola 
 * 
 * This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
Contact info:  megrawm@science.oregonstate.edu
    
 */

public class Main {
    /**
     * Lowest Common Multiplier of a list
     * 
     * @param inList
     * @return
     */
    public static long lcm(long[] inFreqList) {
        long result = inFreqList[0];
        for (int i = 1; i < inFreqList.length; i++)
            result = lcm(result, inFreqList[i]);
        return result;
    }

    private static long lcm(long a, long b) {
        return a * (b / gcd(a, b));
    }

    private static long gcd(long a, long b) {
        while (b > 0) {
            long temp = b;
            b = a % b; // % is remainder
            a = temp;
        }
        return a;
    }
}

Related

  1. lcm(int numberOne, int numberTwo)
  2. lcm(int p, int q)
  3. lcm(int x1, int x2)
  4. lcm(long a, long b)
  5. lcm(long a, long b)
  6. lcm(long u, long v)
  7. lcm(long x, long y)
  8. lcm(long[] a)
  9. LCM1(int A, int B)