Find coefficients x and y such that ax + by = gcd(a, b)
ax + by = gcd(a, b)
function calculateExtendedGCD() {
var a = parseInt(document.getElementById('valA').value);
var b = parseInt(document.getElementById('valB').value);
var outputDiv = document.getElementById('calcOutput');
if (isNaN(a) || isNaN(b)) {
outputDiv.style.display = 'block';
outputDiv.innerHTML = 'Error: Please enter valid integers for both fields.';
return;
}
var originalA = a;
var originalB = b;
// Extended Euclidean Algorithm (Iterative)
var s = 0, old_s = 1;
var t = 1, old_t = 0;
var r = b, old_r = a;
while (r !== 0) {
var quotient = Math.floor(old_r / r);
var temp_r = r;
r = old_r – quotient * r;
old_r = temp_r;
var temp_s = s;
s = old_s – quotient * s;
old_s = temp_s;
var temp_t = t;
t = old_t – quotient * t;
old_t = temp_t;
}
var gcd = old_r;
var coeffX = old_s;
var coeffY = old_t;
var html = '
Calculation Results
';
html += 'Greatest Common Divisor (gcd):' + gcd + '';
html += 'Coefficient x:' + coeffX + '';
html += 'Coefficient y:' + coeffY + '';
html += '';
html += 'Bezout Identity Equation:';
html += '
The Reverse Euclidean Algorithm, mathematically known as the Extended Euclidean Algorithm, is an extension of the standard method used to find the Greatest Common Divisor (GCD) of two integers. While the standard version only provides the GCD, the extended version calculates the coefficients x and y that satisfy Bézout's identity.
What is Bézout's Identity?
Bézout's identity states that for any two integers a and b with a greatest common divisor d, there exist integers x and y such that:
ax + by = gcd(a, b)
These integers x and y are called Bézout coefficients. The process of finding these coefficients by working backward through the steps of the Euclidean algorithm is why it is often referred to as the "Reverse" Euclidean algorithm.
Step-by-Step Example
Let's find the GCD and the coefficients for a = 240 and b = 46.
The Reverse Euclidean Algorithm is not just a theoretical exercise; it is fundamental to modern computer science and cryptography:
Modular Multiplicative Inverse: It is used to find the modular inverse of a number, which is required in the RSA encryption algorithm.
Linear Diophantine Equations: It helps in solving equations of the form ax + by = c.
Chinese Remainder Theorem: The algorithm is a key component in finding solutions for systems of congruences.
How to Use This Calculator
To use the Reverse Euclidean Algorithm calculator, simply enter two positive integers into the input fields. Click "Find Coefficients" to see the GCD, the coefficients x and y, and the full Bézout identity equation. This tool handles large integers and provides the calculation instantly, saving you the manual effort of back-substitution.