Java gcd GCD(long a, long b)

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

Description

GCD

License

Open Source License

Declaration

public static long GCD(long a, long b) 

Method Source Code

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

public class Main {
    public static long GCD(long a, long b) {
        while (a != 0 && b != 0) {
            while ((b & 1) == 0) {
                b >>= 1;//from   w  ww  . j  a v  a  2s.c  o  m
            }
            while ((a & 1) == 0) {
                a >>= 1;
            }
            if (a > b) {
                a -= b;
            } else {
                b -= a;
            }
        }
        return b == 0 ? a : b;
    }
}

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 a, long b)
  7. gcd(long u, long v)
  8. gcd(long x, long y)
  9. gcd(long x, long y)