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

public static long lcm(long a, long b) 

Method Source Code

//package com.java2s;

public class Main {
    public static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }// w w w  .  ja  va2  s .co  m

    public static int lcm(int a, int b) {
        return (int) lcm((long) a, (long) b);
    }

    public static short lcm(short a, short b) {
        return (short) lcm((long) a, (long) b);
    }

    public static byte lcm(byte a, byte b) {
        return (byte) lcm((long) a, (long) b);
    }

    public static long gcd(long a, long b) {
        long r = a;
        a = Math.max(a, b);
        b = Math.min(r, b);

        r = b;
        while (a % b != 0) {
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    }

    public static int gcd(int a, int b) {
        return (int) gcd((long) a, (long) b);
    }

    public static short gcd(short a, short b) {
        return (short) gcd((long) a, (long) b);
    }

    public static byte gcd(byte a, byte b) {
        return (byte) gcd((long) a, (long) b);
    }

    public static float max(float... fs) {
        float max = 0;
        if (fs.length > 0) {
            max = fs[0];
            for (float f : fs) {
                if (f > max) {
                    max = f;
                }
            }
        }
        return max;
    }

    public static double max(double... ds) {
        double max = 0;
        if (ds.length > 0) {
            max = ds[0];
            for (double d : ds) {
                if (d > max) {
                    max = d;
                }
            }
        }
        return max;
    }
}

Related

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