Here you can find the source of lcm(long a, long b)
private static long lcm(long a, long b)
//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; } }