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) { long r = b; while (b > 0) { r = b;//w w w .j a v a 2s . c o m b = a % b; a = r; } return r; } public static long gcd(long[] a) { if (a.length == 1) { return a[0]; } else { long gcd = 1; for (int i = 0; i < a.length; i++) { if (i == 0) { gcd = gcd(a[i], a[i + 1]); } else { gcd = gcd(a[i], gcd); } } return gcd; } } }