Java lcm lcm(int a, int b)

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

Description

lcm

License

Open Source License

Parameter

Parameter Description
a a parameter
b a parameter

Return

the least common multiple of a and b

Declaration

public static int lcm(int a, int b) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//  ww w .  j a  v a2 s  . c o m
     * @param a
     * @param b
     * @return the least common multiple of {@code a} and {@code b}
     */
    public static int lcm(int a, int b) {
        return a * (b / gcd(a, b));
    }

    /**
     * @param a
     * @param b
     * @return the least common multiple of {@code a} and {@code b}
     */
    public static long lcm(long a, long b) {
        return a * (b / gcd(a, b));
    }

    /**
     * @param a
     * @param b
     * @return the greatest common divisor of {@code a} and {@code b}
     */
    public static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    /**
     * @param a
     * @param b
     * @return the greatest common divisor of {@code a} and {@code b}
     */
    public static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }
}

Related

  1. LCM(double a, double b)
  2. lcm(int a, int b)
  3. lcm(int a, int b)
  4. lcm(int a, int b)
  5. lcm(int a, int b)
  6. lcm(int a, int b)
  7. lcm(int a, int b)
  8. lcm(int a, int b)
  9. lcm(int a, int b)