Here you can find the source of gcdExtended(BigInteger p, BigInteger q)
public static BigInteger[] gcdExtended(BigInteger p, BigInteger q)
//package com.java2s; //License from project: Open Source License import java.math.BigInteger; public class Main { public static BigInteger[] gcdExtended(BigInteger p, BigInteger q) { if (q.equals(BigInteger.ZERO)) return new BigInteger[] { p, BigInteger.ONE, BigInteger.ZERO }; BigInteger[] vector = gcdExtended(q, p.mod(q)); BigInteger d = vector[0]; BigInteger a = vector[2]; BigInteger b = vector[1].subtract(p.divide(q).multiply(vector[2])); return new BigInteger[] { d, a, b }; }//from w w w . j a v a2 s .c o m }