public static int gcd(int a, int b) {
int n1 = Math.abs(a); int n2 = Math.abs(b); int remainder = n1 % n2; while (remainder > 0) { n1 = n2; n2 = remainder; remainder = n1 % n2; } return n2; }