L15 Euclid's Algorithm
L15 Euclid's Algorithm
Introduction
Euclidean algorithm or Euclid's algorithm, is an efficient method for computing
the greatest common divisor (GCD) of two integers (numbers), the largest
number that divides them both without a remainder.
First the two numbers are subjected to prime factorizations, and the common
factors of the two prime factorizations are multiplied to get the GCD
Idea
The algorithm is based on the below facts:
ax + by = gcd(a, b)
The extended Euclidean algorithm updates results of gcd(a, b) using the results
calculated by recursive call gcd(b%a, a).
x = y1 - ⌊b/a⌋ * x1
y = x1
The extended Euclidean algorithm is particularly useful when a and b are coprime.
Similarly, the polynomial extended Euclidean algorithm allows one to compute the
multiplicative inverse in algebraic field extensions and, in particular in finite fields
of non prime order.
It follows that both extended Euclidean algorithms are widely used in cryptography.
return gcd;
}
public static void main(String[] args)
{
int x=1, y=1;
int a = 35, b = 15;
int g = gcdExtended(a, b, x, y);
System.out.print("GCD is " + g);
}
}
THANK YOU