{
    "name": "Extended Euclidean Algorithm Calculator",
    "url": "https://calculators.geekmidst.com/calculators/extended-euclidean-algorithm-calculator",
    "markdown": "https://calculators.geekmidst.com/calculators/extended-euclidean-algorithm-calculator.md",
    "category": "Algebra, geometry & advanced math",
    "description": "Find gcd(a, b) and integers x, y with ax + by = gcd, the modular inverse when it exists, and every step of the extended Euclidean algorithm.",
    "summary": "The extended Euclidean algorithm finds the greatest common divisor and the Bézout coefficients x and y with ax + by = gcd(a, b). When the gcd is 1, x is the inverse of a modulo b.",
    "also_called": [
        "Bézout identity calculator",
        "Modular inverse calculator"
    ],
    "applies_to": "Worldwide",
    "last_updated": "2026-10-29",
    "computation": "Results are computed in the visitor’s browser on the HTML page. This API describes the calculator; it does not compute results.",
    "inputs": [
        {
            "name": "a",
            "label": "a",
            "type": "text",
            "default": "240"
        },
        {
            "name": "b",
            "label": "b (modulus for the inverse)",
            "type": "text",
            "default": "46"
        }
    ],
    "outputs": [
        {
            "key": "gcd",
            "label": "gcd(a, b)",
            "format": "text"
        },
        {
            "key": "x",
            "label": "x (coefficient of a)",
            "format": "text"
        },
        {
            "key": "y",
            "label": "y (coefficient of b)",
            "format": "text"
        },
        {
            "key": "identity",
            "label": "Bézout identity",
            "format": "text"
        },
        {
            "key": "inverse",
            "label": "Inverse of a modulo b",
            "format": "text"
        },
        {
            "key": "lcm",
            "label": "lcm(a, b)",
            "format": "text"
        },
        {
            "key": "steps",
            "label": "Division steps",
            "format": "integer"
        }
    ],
    "formula": {
        "text": "r₀ = a, r₁ = b; qᵢ = ⌊rᵢ₋₁ ÷ rᵢ⌋, rᵢ₊₁ = rᵢ₋₁ − qᵢ·rᵢ, and likewise sᵢ₊₁ = sᵢ₋₁ − qᵢ·sᵢ, tᵢ₊₁ = tᵢ₋₁ − qᵢ·tᵢ (s: 1, 0; t: 0, 1) until r = 0",
        "variables": {
            "r": "remainders",
            "q": "quotients",
            "s, t": "running coefficients with rᵢ = sᵢ·a + tᵢ·b"
        }
    },
    "worked_example": {
        "inputs": {
            "a": "240",
            "b": "46"
        },
        "steps": [
            "240 = 5 × 46 + 10; 46 = 4 × 10 + 6; 10 = 1 × 6 + 4; 6 = 1 × 4 + 2; 4 = 2 × 2 + 0, so gcd = 2.",
            "Back-substituting the quotients gives s = −9 and t = 47.",
            "Check: 240 × (−9) + 46 × 47 = −2160 + 2162 = 2."
        ],
        "result": "gcd(240, 46) = 2 = 240 × (−9) + 46 × 47. There is no inverse of 240 mod 46 because the gcd is not 1."
    },
    "interpretation": "If the gcd is 1, a and b are coprime and x mod b is the modular inverse of a, which is needed for RSA keys, solving linear congruences and the Chinese remainder theorem.",
    "assumptions": [
        "Exact big-integer arithmetic.",
        "x and y are the pair the standard algorithm produces; adding k·b/g to x and subtracting k·a/g from y gives the others."
    ],
    "limitations": [
        "Inputs are capped at 200 digits each."
    ],
    "rules": null,
    "faqs": [
        {
            "question": "Are x and y unique?",
            "answer": "No. If (x, y) works, so does (x + k·b/g, y − k·a/g) for any integer k. The algorithm returns the pair with the smallest magnitudes."
        },
        {
            "question": "How do I get a positive inverse?",
            "answer": "Take x mod b. For a = 3 and b = 11, x = 4, and 3 × 4 = 12 ≡ 1 (mod 11)."
        }
    ],
    "sources": [],
    "related": [
        {
            "name": "Greatest Common Factor Calculator",
            "url": "https://calculators.geekmidst.com/calculators/greatest-common-factor-calculator"
        },
        {
            "name": "Chinese Remainder Theorem Calculator",
            "url": "https://calculators.geekmidst.com/calculators/chinese-remainder-theorem-calculator"
        },
        {
            "name": "Modular Exponentiation Calculator",
            "url": "https://calculators.geekmidst.com/calculators/modular-exponentiation-calculator"
        }
    ],
    "disclaimer": null,
    "publisher": "GM¹X CalcVerse"
}