Here you can find the source of lcm(long a, long b)
a
and b
Parameter | Description |
---|---|
a | Value a |
b | Value b |
public static long lcm(long a, long b)
//package com.java2s; //License from project: LGPL public class Main { /**// w ww .ja v a 2 s . com * Calculates lowest common multiple (LCM) of two integer values * <code>a</code> and <code>b</code> * * @param a * Value a * @param b * Value b */ public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } /** * Calculates greatest common divisor (GCD) of two integer values * <code>a</code> and <code>b</code> * * @param a * Value a * @param b * Value b */ public static long gcd(long a, long b) { if (a == 0) return b; if (b == 0) return a; if (a == b) return a; if (a == 1 | b == 1) return 1; if ((a % 2 == 0) & (b % 2 == 0)) return 2 * gcd(a / 2, b / 2); if ((a % 2 == 0) & (b % 2 != 0)) return gcd(a / 2, b); if ((a % 2 != 0) & (b % 2 == 0)) return gcd(a, b / 2); return gcd(b, Math.abs(a - b)); } }