The Euclidean Algorithm

How do you find the largest number that divides both 1071 and 462? You must do this without factoring either one. Factoring large numbers is slow. For numbers with hundreds of digits, it is computationally infeasible even for modern computers. Yet the question of a common divisor is fundamental to nearly all of number theory. It matters for simplifying fractions and for building and breaking cryptographic systems. The Euclidean Algorithm answers this question with breathtaking efficiency. It uses nothing more than repeated division with remainder. The idea was recorded by Euclid around 300 BCE. It appears in Book VII of the Elements. It is one of the oldest algorithms in continuous use. It replaces a hard problem with a short sequence of easy problems. That hard problem is finding common divisors of two possibly huge numbers. Each easy problem is a division with a smaller remainder than the last. The remainders shrink so fast that the whole process terminates quickly. The last nonzero remainder is provably the greatest common divisor. The big picture is this: divisibility questions about a pair of integers can be reduced. They reduce, without loss of information, to divisibility questions about a strictly smaller pair. This reduction step is reversible. That reversibility is exactly what lets us compute the gcd. It also lets us later express it as an integer combination of the original two numbers. This happens in the Extended Euclidean Algorithm. It is the seed of Bezout's Identity. This article gives the precise algorithm. It proves the algorithm terminates in finitely many steps. It also proves rigorously that its output equals gcd⁡(a,b)\gcd(a,b). It relies only on Divisibility and the Division Algorithm and the definition of The Greatest Common Divisor. Both of these are assumed known. It sets up the machinery needed for The Extended Euclidean Algorithm.

Key takeaways
  • The Euclidean Algorithm computes gcd⁡(a,b)\gcd(a,b) using only repeated division with remainder — no factoring required.
  • Its core fact: gcd⁡(a,b)=gcd⁡(b,r)\gcd(a,b) = \gcd(b, r) whenever a=bq+ra = bq + r, for any valid quotient-remainder pair.
  • Applying this repeatedly produces a strictly decreasing sequence of nonnegative remainders, forcing termination.
  • The last nonzero remainder in the chain is exactly gcd⁡(a,b)\gcd(a,b).
  • Its running time is polynomial in the number of digits, and worst-case behavior is governed by Fibonacci numbers.
  • Key idea: replace gcd⁡(a,b)\gcd(a,b) by gcd⁡(b,a  b)\gcd(b, a \bmod b) over and over; the gcd never changes, and the numbers shrink until one hits zero.

Where this lives today

The Euclidean Algorithm is the computational backbone of elementary number theory and remains indispensable in modern computing. In cryptography, the Extended Euclidean Algorithm — a light extension of this procedure that also tracks Bezout coefficients — is used to compute modular inverses in RSA key generation and in elliptic-curve cryptography. In computer algebra systems, it underlies polynomial gcd computation (via an analogous algorithm on polynomials over a field), which in turn is essential for simplifying rational functions and factoring. In simplifying fractions, the algorithm reduces a/ba/b to lowest terms by dividing numerator and denominator by gcd⁡(a,b)\gcd(a,b). In the analysis of algorithms, it is the textbook example for proving termination via a strictly decreasing well-ordered quantity, and Lamé's theorem connecting its worst-case behavior to Fibonacci numbers is a classic result in complexity analysis. It also appears in continued fraction expansions: the sequence of quotients q1,q2,…q_1, q_2, \dots produced by the algorithm applied to aa and bb is exactly the continued fraction expansion of a/ba/b, linking gcd computation to Diophantine approximation.

Ask the tutor: How does tracking coefficients through the Euclidean Algorithm's steps produce the Bezout coefficients x,yx, y with ax+by=gcd⁡(a,b)ax+by=\gcd(a,b)?

DefinitionThe Euclidean Algorithm

Let a,ba, b be integers, not both zero. Assume without loss of generality b≠0b \neq 0 (if b=0b = 0 and a≠0a\neq0, then gcd⁡(a,0)=∣a∣\gcd(a,0) = |a| by definition, and no division is needed). Define a sequence of pairs (r−1,r0),(r0,r1),(r1,r2),…(r_{-1}, r_0), (r_0, r_1), (r_1, r_2), \dots by setting

r−1=a,r0=b,r_{-1} = a, \qquad r_0 = b,

and, as long as rk≠0r_k \neq 0, applying the Division Algorithm to write

rk−1=qk+1 rk+rk+1,0≤rk+1<∣rk∣,r_{k-1} = q_{k+1} \, r_k + r_{k+1}, \qquad 0 \le r_{k+1} < |r_k|,

for k=0,1,2,…k = 0, 1, 2, \dots. The Euclidean Algorithm is the procedure of repeating this division step until some remainder rn+1=0r_{n+1} = 0 is reached. Its output is the last nonzero remainder, rnr_n (with the convention that if r0=b=0r_0 = b = 0 already, the output is ∣a∣|a|).

Intuition

Think of gcd⁡(a,b)\gcd(a,b) as a shared "unit of measurement" for two lengths aa and bb. If you lay the shorter length bb down along the longer length aa as many times as it fits, a leftover piece rr remains with r<br < b. Any ruler that measures both aa and bb exactly must also measure this leftover piece exactly — and conversely, any ruler measuring bb and rr exactly also measures aa. So the pair (a,b)(a,b) and the pair (b,r)(b,r) have exactly the same common measuring-sticks, hence the same greatest one. This is the entire content of the algorithm: replace (a,b)(a,b) by the strictly smaller pair (b,r)(b,r), and repeat. Since remainders are nonnegative integers that strictly decrease at every step, the process cannot continue forever — it must hit a remainder of 00, at which point the previous remainder is the answer. A second way to see it: picture the Euclidean algorithm as repeatedly subtracting the smaller number from the larger (division is just repeated subtraction done all at once). Geometrically, this is the ancient process of finding the largest square tile that exactly tiles an a×ba \times b rectangle — lay down b×bb\times b squares along the length aa, leave a strip of width r<br < b, then tile that strip with squares of the next size down, and so on.

Figure
Euclidean Algorithm on (1071, 462): remainders shrink to the gcd, 21
Step-by-step reduction of the pair (1071, 462) a = 1071 462 + 462 + r = 1071, r = 147 b = 462 147×3 + r = 462, r = 21 147 21×7 + 0 = 147 — remainder hits 0 gcd(1071, 462) = 21 (last nonzero remainder)
TheoremCorrectness and Termination of the Euclidean Algorithm

Let a,ba,b be integers with b≠0b \neq 0. Define the sequence r−1=ar_{-1} = a, r0=br_0 = b, and for each k≥0k \ge 0 with rk≠0r_k \neq 0, let qk+1,rk+1q_{k+1}, r_{k+1} be the unique integers given by the Division Algorithm satisfying

rk−1=qk+1rk+rk+1,0≤rk+1<∣rk∣.r_{k-1} = q_{k+1} r_k + r_{k+1}, \qquad 0 \le r_{k+1} < |r_k|.

Then: 1. (Termination) There exists a smallest index n≥0n \ge 0 such that rn+1=0r_{n+1} = 0; that is, the sequence of divisions terminates after finitely many steps. 2. (Correctness) If n=0n = 0 (i.e. r1=0r_1 = 0 immediately), then gcd⁡(a,b)=∣r0∣=∣b∣\gcd(a,b) = |r_0| = |b|. If n≥1n \ge 1, then

gcd⁡(a,b)=rn,\gcd(a,b) = r_n,

the last nonzero remainder produced by the algorithm.

Proof

Step 0: a key lemma about divisibility of remainders.

∎

lemma[Invariance of gcd under division with remainder] If a=qb+ra = qb + r for integers a,b,q,ra,b,q,r with b≠0b \neq 0, then

gcd⁡(a,b)=gcd⁡(b,r).\gcd(a,b) = \gcd(b,r).

::: Proof of Lemma. Let d=gcd⁡(a,b)d = \gcd(a,b) and d′=gcd⁡(b,r)d' = \gcd(b,r). (Both exist: b≠0b\neq 0 guarantees gcd⁡(a,b)\gcd(a,b) exists by definition of gcd; and since b≠0b \neq 0, gcd⁡(b,r)\gcd(b,r) exists as well, as bb alone is a nonzero common divisor candidate — more precisely, gcd of two integers not both zero always exists, and here b≠0b \neq 0.) We show d∣d′d \mid d''s defining set of common divisors matches, by showing the set of common divisors of (a,b)(a,b) equals the set of common divisors of (b,r)(b,r). (⊆\subseteq) Suppose c∣ac \mid a and c∣bc \mid b. Since r=a−qbr = a - qb, and cc divides both terms on the right (as c∣ac\mid a, and c∣b⇒c∣qbc \mid b \Rightarrow c \mid qb), it follows c∣rc \mid r. So cc is a common divisor of bb and rr. (⊇\supseteq) Suppose c∣bc \mid b and c∣rc \mid r. Since a=qb+ra = qb + r, and cc divides both terms on the right, it follows c∣ac \mid a. So cc is a common divisor of aa and bb. Thus the common divisors of (a,b)(a,b) are exactly the common divisors of (b,r)(b,r); in particular these two sets have the same maximum element, so d=d′d = d'. ■\blacksquare (Lemma)

Step 1: Termination. Consider the sequence of remainders r0,r1,r2,…r_0, r_1, r_2, \dots produced as long as they are defined (i.e. as long as the previous remainder is nonzero). By the Division Algorithm's conclusion applied at each step,

0≤rk+1<∣rk∣whenever rk≠0.0 \le r_{k+1} < |r_k| \quad \text{whenever } r_k \neq 0.

Hence, as long as no remainder in the sequence is zero, we get a strictly decreasing chain of nonnegative integers

∣b∣=∣r0∣>r1>r2>r3>⋯≥0.|b| = |r_0| > r_1 > r_2 > r_3 > \cdots \ge 0.

(Here we use r1<∣r0∣r_1 < |r_0| from the first division, and thereafter rk+1<rkr_{k+1} < r_k since rk≥0r_k \ge 0 for k≥1k\ge 1 so ∣rk∣=rk|r_k| = r_k.) A strictly decreasing sequence of nonnegative integers cannot be infinite: by the well-ordering principle, any nonempty set of nonnegative integers has a least element, and a strictly decreasing infinite sequence would produce a subset with no least element (take the sequence itself as the set — for any term, a later term is smaller), a contradiction. Therefore the sequence r1,r2,r3,…r_1, r_2, r_3, \dots must reach 00 after finitely many terms. Let n+1n+1 be the first index with rn+1=0r_{n+1} = 0 (if r1=0r_1 = 0 already, then n=0n = 0). This proves termination, establishing part 1.

Step 2: Correctness. We prove by induction on kk, for k=0,1,…,nk = 0, 1, \dots, n, the statement

P(k):gcd⁡(rk−1,rk)=gcd⁡(a,b).P(k): \qquad \gcd(r_{k-1}, r_k) = \gcd(a,b).

Base case k=0k = 0: P(0)P(0) asserts gcd⁡(r−1,r0)=gcd⁡(a,b)\gcd(r_{-1}, r_0) = \gcd(a,b), which is immediate since r−1=a,r0=br_{-1} = a, r_0 = b by definition. Inductive step: Suppose P(k)P(k) holds for some 0≤k<n0 \le k < n, i.e. gcd⁡(rk−1,rk)=gcd⁡(a,b)\gcd(r_{k-1}, r_k) = \gcd(a,b), and rk≠0r_k \neq 0 (guaranteed since k<nk < n implies the division defining rk+1r_{k+1} took place, requiring rk≠0r_k \neq 0). By construction,

rk−1=qk+1rk+rk+1,r_{k-1} = q_{k+1} r_k + r_{k+1},

so applying the Lemma with (a,b,q,r)=(rk−1,rk,qk+1,rk+1)(a,b,q,r) = (r_{k-1}, r_k, q_{k+1}, r_{k+1}) gives

gcd⁡(rk−1,rk)=gcd⁡(rk,rk+1).\gcd(r_{k-1}, r_k) = \gcd(r_k, r_{k+1}).

Combined with the inductive hypothesis gcd⁡(rk−1,rk)=gcd⁡(a,b)\gcd(r_{k-1},r_k) = \gcd(a,b), we conclude

gcd⁡(rk,rk+1)=gcd⁡(a,b),\gcd(r_k, r_{k+1}) = \gcd(a,b),

which is exactly P(k+1)P(k+1). This completes the induction, valid for all kk from 00 to nn. In particular, P(n)P(n) gives

gcd⁡(rn−1,rn)=gcd⁡(a,b).\gcd(r_{n-1}, r_n) = \gcd(a,b).

Case n=0n = 0: Then P(0)P(0) directly gives gcd⁡(a,b)=gcd⁡(r−1,r0)=gcd⁡(a,b)\gcd(a,b) = \gcd(r_{-1},r_0) = \gcd(a,b) trivially — but we want to identify this with ∣b∣|b|. Since r1=0r_1 = 0, by definition of gcd, gcd⁡(b,0)=∣b∣\gcd(b, 0) = |b| (as every integer divides 00, so the common divisors of bb and 00 are exactly the divisors of bb, whose greatest element is ∣b∣|b|, assuming b≠0b \neq 0). And P(0)P(0) says gcd⁡(a,b)=gcd⁡(r−1,r0)=gcd⁡(a,b)\gcd(a,b) = \gcd(r_{-1},r_0) = \gcd(a,b) — to close the loop, note n=0n=0 means r1=0r_1 = 0 was reached on the first division a=q1b+r1a = q_1 b + r_1, and the Lemma applied directly gives gcd⁡(a,b)=gcd⁡(b,r1)=gcd⁡(b,0)=∣b∣\gcd(a,b) = \gcd(b, r_1) = \gcd(b,0) = |b|. This matches the claimed output ∣r0∣=∣b∣|r_0| = |b|. Case n≥1n \ge 1: Since rn+1=0r_{n+1} = 0 is the first zero remainder, we know rn≠0r_n \neq 0 (else nn would not be the last valid index with a nonzero remainder producing a further division — more precisely rn≠0r_n \ne 0 by minimality of n+1n+1 as the first zero index, since rnr_n is not zero as n<n+1n < n+1). Now since rn+1=0r_{n+1} = 0, the same computation as above (Lemma applied to rn−1=qn+1rn+rn+1r_{n-1} = q_{n+1} r_n + r_{n+1}) gives

gcd⁡(rn−1,rn)=gcd⁡(rn,rn+1)=gcd⁡(rn,0)=∣rn∣=rn,\gcd(r_{n-1}, r_n) = \gcd(r_n, r_{n+1}) = \gcd(r_n, 0) = |r_n| = r_n,

using rn≥0r_n \ge 0 (indeed rn>0r_n > 0) from the Division Algorithm. Combining with P(n)P(n): gcd⁡(a,b)=gcd⁡(rn−1,rn)=rn\gcd(a,b) = \gcd(r_{n-1},r_n) = r_n. This proves gcd⁡(a,b)=rn\gcd(a,b) = r_n, the last nonzero remainder, completing part 2 and the theorem. ■\blacksquare

Worked examples

Example 1: gcd⁡(2024,748)\gcd(2024, 748). We apply the algorithm, dividing the larger by the smaller at each stage and tracking quotient and remainder explicitly.

2024=2⋅748+5282024 = 2 \cdot 748 + 528
748=1⋅528+220748 = 1 \cdot 528 + 220
528=2⋅220+88528 = 2 \cdot 220 + 88
220=2⋅88+44220 = 2 \cdot 88 + 44
88=2⋅44+088 = 2 \cdot 44 + 0

The last nonzero remainder is 4444. By the theorem, gcd⁡(2024,748)=44\gcd(2024, 748) = 44. Check: 2024=44⋅462024 = 44 \cdot 46 and 748=44⋅17748 = 44 \cdot 17, and gcd⁡(46,17)=1\gcd(46,17)=1 since 1717 is prime and does not divide 4646. So indeed 4444 is the greatest common divisor — consistent with the algorithm's output.

Example 2: gcd⁡(−357,1155)\gcd(-357, 1155), illustrating a negative input. Since gcd⁡\gcd is typically defined via divisibility (which does not care about sign), we may take a=−357a = -357, b=1155b = 1155, or equivalently work with gcd⁡(357,1155)\gcd(357, 1155) since the set of common divisors of {a,b}\{a,b\} is unaffected by replacing an argument with its absolute value (any c∣a  ⟺  c∣−ac \mid a \iff c \mid -a). We proceed with r−1=1155r_{-1} = 1155, r0=357r_0 = 357 (ordering so the Division Algorithm applies cleanly with a positive divisor):

1155=3⋅357+841155 = 3 \cdot 357 + 84
357=4⋅84+21357 = 4 \cdot 84 + 21
84=4⋅21+084 = 4 \cdot 21 + 0

The last nonzero remainder is 2121, so gcd⁡(357,1155)=21\gcd(357, 1155) = 21, and hence gcd⁡(−357,1155)=21\gcd(-357, 1155) = 21 as well. Check: 357=21⋅17357 = 21 \cdot 17 and 1155=21⋅551155 = 21 \cdot 55, with gcd⁡(17,55)=1\gcd(17, 55) = 1 (since 1717 is prime and 17∤5517 \nmid 55). This confirms 2121 is correct.

CounterexampleWhy we need b≠0b \neq 0 at each division step

The theorem's proof crucially applies the Division Algorithm to rk−1=qk+1rk+rk+1r_{k-1} = q_{k+1}r_k + r_{k+1}, which requires rk≠0r_k \neq 0 (the Division Algorithm is only stated, and only true, for a nonzero divisor). Suppose we try to drop this hypothesis and "divide by zero" anyway — say naively attempt

88=q⋅0+r88 = q \cdot 0 + r

when a remainder happens to be 00 (as in Example 1's last line, 88=2⋅44+088 = 2\cdot 44 + 0, followed by an attempted next step "44=q⋅0+r44 = q\cdot 0 + r"). There is no valid quotient-remainder pair with 0≤r<∣0∣=00 \le r < |0| = 0, since no nonnegative integer is strictly less than 00. The Division Algorithm's conclusion is vacuous or undefined here — division by 00 is simply not permitted. If one ignored this and, say, declared r=44r = 44 and continued the sequence indefinitely without ever stopping, termination would fail: the "sequence" 44,44,44,…44, 44, 44, \dots neither decreases nor reaches a legitimate end, and the inductive argument for correctness (Step 2 of the proof) would break down entirely, since P(k+1)P(k+1) was derived precisely from a genuine application of the Lemma requiring a valid division. This shows why the algorithm's very definition insists on stopping exactly when a remainder hits 00, rather than trying to divide by that zero remainder.

Scope, edge cases & common traps

SituationWhat happensWhy
b=0b = 0, a≠0a \neq 0No division performed; output is ∣a∣|a| directlygcd⁡(a,0)=∣a∣\gcd(a,0) = |a| by definition of gcd
a=b=0a = b = 0gcd⁡(0,0)\gcd(0,0) is undefined (or by convention 00)Every integer divides 00, so there is no greatest divisor unless a convention is fixed
Negative inputsReplace a,ba,b by ∣a∣,∣b∣|a|,|b| first, or note the algorithm still works since remainders are forced nonnegative by the Division AlgorithmDivisibility and gcd depend only on absolute values
One input divides the other exactlyAlgorithm terminates in one step; output is min⁡(∣a∣,∣b∣)\min(|a|,|b|)The remainder is 00 immediately
Worst-case input sizeConsecutive Fibonacci numbers Fn+1,FnF_{n+1}, F_nEach step produces quotient 11, the slowest possible decrease, giving O(log⁡min⁡(a,b))O(\log \min(a,b)) steps — Lamé's theorem

The mathematician behind it

Origins · 1 minEuclid of Alexandria and how this was discovered
EO
Euclid of Alexandria
fl. c. 300 BCE · Ptolemaic Egypt

Euclid is known almost entirely through his mathematical writing rather than biographical record; even his birthplace and dates are uncertain, and some historians have questioned whether "Euclid" designates a single author or a school. His Elements, a thirteen-book compilation and systematization of geometry and number theory, became the most reproduced mathematical text in history, shaping mathematical exposition — the very idea of building rigorously from definitions and axioms to theorems — for over two millennia. Propositions VII.1 and VII.2 of the Elements present the algorithm for finding the greatest common measure of two magnitudes, phrased geometrically via repeated subtraction, precisely the algorithm treated in this article.

History
- c. 300 BCE — Euclid presents the algorithm geometrically, as repeated subtraction of the smaller magnitude from the larger, in Book VII of the Elements.
- 1st millennium CE — Indian and Islamic mathematicians (including Āryabhaṭa, 5th century CE) adapt the algorithm's repeated-subtraction structure for solving linear Diophantine equations, foreshadowing Bezout's identity.
- 1844 — Gabriel Lamé proves that the number of steps of the Euclidean algorithm on inputs up to NN is O(log⁡N)O(\log N), using the Fibonacci sequence to establish the worst case.
- 1969 — Donald Knuth's The Art of Computer Programming analyzes the algorithm's average-case running time, cementing its role as a foundational example in algorithm analysis.
- 1970s–present — Variants (binary GCD, extended Euclidean algorithm) become core primitives in computational number theory and cryptographic software.
Why does the Euclidean Algorithm always terminate?

Because each division step produces a remainder that is strictly smaller than the divisor used, and remainders are always nonnegative integers by the Division Algorithm. This creates a strictly decreasing sequence of nonnegative integers, ∣b∣>r1>r2>⋯≥0|b| > r_1 > r_2 > \cdots \ge 0. Such a sequence cannot decrease forever, since the well-ordering principle guarantees every nonempty set of nonnegative integers has a least element — an infinite strictly decreasing sequence would contradict this. Hence the sequence must reach 00 after finitely many steps, at which point the algorithm halts. In fact the number of steps is at most roughly 55 times the number of decimal digits of the smaller input, by Lamé's theorem, so termination is not just guaranteed but fast.

Does the order in which I feed the two numbers matter?

Not for correctness, only for the number of steps. If you start with (a,b)(a,b) where a<ba < b, the very first division a=0⋅b+aa = 0\cdot b + a simply swaps the roles, since q1=0q_1 = 0 and r1=ar_1 = a, and the algorithm proceeds identically to starting from (b,a)(b,a). So feeding the smaller number first costs at most one extra trivial step but produces the same final gcd. Some implementations explicitly swap so that the larger number is always divided by the smaller, purely as a minor efficiency convention, not because the mathematics requires it.

What happens if I try to compute gcd⁡(0,0)\gcd(0,0) with this algorithm?

The algorithm as stated requires b≠0b \neq 0 to perform even the first division, since the Division Algorithm needs a nonzero divisor. If both a=0a=0 and b=0b=0, there is no division to perform and no well-defined "greatest" common divisor, because every integer divides 00, so the divisors of the pair (0,0)(0,0) have no maximum. Most texts either leave gcd⁡(0,0)\gcd(0,0) undefined or adopt the convention gcd⁡(0,0)=0\gcd(0,0)=0 by fiat; the Euclidean Algorithm itself simply does not apply to this degenerate input and should be special-cased before running.

How is this related to the Extended Euclidean Algorithm and Bezout's Identity?

The Euclidean Algorithm computes only the numerical value of gcd⁡(a,b)\gcd(a,b). The Extended Euclidean Algorithm runs the same sequence of divisions but additionally tracks, at each step, coefficients expressing each remainder rkr_k as an integer combination xka+ykbx_k a + y_k b. Since the final nonzero remainder rnr_n equals gcd⁡(a,b)\gcd(a,b), its tracked coefficients xn,ynx_n, y_n satisfy gcd⁡(a,b)=xna+ynb\gcd(a,b) = x_n a + y_n b — this is precisely Bezout's Identity. The two algorithms share the identical division steps; the extended version simply carries extra bookkeeping alongside them.

Can this algorithm be used on polynomials, not just integers?

Yes. Over a field (such as the rationals or reals), polynomials support an analogous division algorithm with remainder of strictly smaller degree, and the same repeated-division procedure computes the gcd of two polynomials. The termination argument is identical in spirit, replacing "strictly decreasing nonnegative integer" with "strictly decreasing nonnegative degree." This polynomial Euclidean algorithm is a workhorse of computer algebra systems for simplifying rational expressions and factoring.

Is there a faster algorithm than this for computing gcd?

For arbitrary-size integers, the standard Euclidean Algorithm already runs in time polynomial in the number of digits — specifically O(log⁡min⁡(a,b))O(\log \min(a,b)) division steps by Lamé's theorem — which is extremely fast in practice. Variants like the binary GCD algorithm (which replaces division by bit shifts and subtraction) can be faster in low-level hardware implementations by avoiding costly division operations, and more advanced algorithms (based on fast integer multiplication, e.g. the Schönhage–Strassen approach) achieve near-linear time for very large inputs, but the classical Euclidean Algorithm remains the standard teaching and reference algorithm due to its simplicity and provable correctness.

Why does the Lemma's proof work with arbitrary integer cc, not just prime divisors?

The proof shows that the entire set of common divisors of (a,b)(a,b) coincides with the entire set of common divisors of (b,r)(b,r), using only the basic fact that divisibility is preserved under addition and integer multiples (c∣xc\mid x and c∣yc \mid y implies c∣(x+y)c \mid (x+y) and c∣mxc\mid mx for any integer mm). This works for any integer cc, positive or negative, prime or composite — the argument never needs unique factorization or primality. That is precisely why the Euclidean Algorithm can compute gcds without ever factoring the numbers involved, which is the whole point of its efficiency advantage over factorization-based methods.

Before this

Where this leads