Here you can find the source of gcd(BigInteger a, BigInteger b)
public static BigInteger gcd(BigInteger a, BigInteger b)
//package com.java2s; import java.math.BigInteger; public class Main { public static int gcd(int a, int b) { if (a < b) { int t = b; b = a;// w ww .j a v a2 s .co m a = t; } int r; do { r = a % b; a = b; b = r; } while (r != 0); return a; } public static long gcd(long a, long b) { if (a < b) { long t = b; b = a; a = t; } long r; do { r = a % b; a = b; b = r; } while (r != 0); return a; } public static BigInteger gcd(BigInteger a, BigInteger b) { if (a.compareTo(b) < 0) { BigInteger t = b; b = a; a = t; } BigInteger r = null; do { r = a.mod(b); a = b; b = r; } while (!r.equals(BigInteger.ZERO)); return a; } }