Java gcd gcd(long a, long b)

Here you can find the source of gcd(long a, long b)

Description

Greatest common divisor using Euclides algorithm.

License

Open Source License

Parameter

Parameter Description
a One of the values
b The other value

Return

The greatest common divisor

Declaration

public static long gcd(long a, long b) 

Method Source Code

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

public class Main {
    /**/*  w w  w.  j av a2s  . co m*/
     * Greatest common divisor using Euclides algorithm.
     *
     * @param a One of the values
     * @param b The other value
     * @return The greatest common divisor
     */
    public static long gcd(long a, long b) {
        while (b != 0) {
            long n = a % b;
            a = b;
            b = n;
        }
        return a;
    }
}

Related

  1. gcd(long a, long b)
  2. GCD(long a, long b)
  3. gcd(long a, long b)
  4. gcd(long a, long b)
  5. GCD(long a, long b)
  6. gcd(long u, long v)
  7. gcd(long x, long y)
  8. gcd(long x, long y)
  9. gcd(long[] array)