Java BigInteger Calculate gcdExtended(BigInteger p, BigInteger q)

Here you can find the source of gcdExtended(BigInteger p, BigInteger q)

Description

gcd Extended

License

Open Source License

Declaration

public static BigInteger[] gcdExtended(BigInteger p, BigInteger q) 

Method Source Code


//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
}

Related

  1. gcd(BigInteger a, BigInteger b)
  2. GCD(BigInteger x, BigInteger y)
  3. gcd(BigInteger... values)
  4. gcd(Iterable nums)
  5. gcdEuclides(BigInteger a, BigInteger b)
  6. getAddressText(BigInteger address)
  7. getByteArrayFromBigIntegerArray(Object value)
  8. getBytes(BigInteger bi, int minLen)
  9. getBytes(BigInteger big, int bitlen)