Java lcm LCM(int m, int n)

Here you can find the source of LCM(int m, int n)

Description

LCM

License

Open Source License

Return

lcm(|m|, |n|)

Declaration

static private int LCM(int m, int n) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from w  ww .jav  a2 s.  co  m*/
     * @return lcm(|m|, |n|)
     */
    static private int LCM(int m, int n) {
        if (m < 0) {
            m = -m;
        }
        if (n < 0) {
            n = -n;
        }
        return m * (n / GCD(m, n)); // parentheses important to avoid overflow
    }

    /**
     * @return gcd(|m|, |n|)
     */
    static private int GCD(int m, int n) {
        if (m < 0) {
            m = -m;
        }
        if (n < 0) {
            n = -n;
        }
        if (0 == n) {
            return m;
        } else {
            return GCD(n, m % n);
        }
    }
}

Related

  1. lcm(int a, int 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 m, int n)
  7. lcm(int n, int m)
  8. lcm(int num1, int num2)
  9. lcm(int num1, int num2)