Here you can find the source of GCD(long a, long b)
public static long GCD(long a, long b)
//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; } }