2.5.7 · D5Number Theory (Intermediate)
Question bank — Euclidean algorithm — GCD computation
Before we start, two words we lean on constantly:
- Divides — we say divides (written ) when is an exact multiple of , i.e. for some whole number , no remainder. Picture as a row of dots that can be split into equal groups of size with none left over.
- GCD — the greatest common divisor is the biggest number that divides both and . Picture the largest tile that covers both an -length and a -length ruler with no gaps.
True or false — justify
The step-relation only holds when
False — if then , so it becomes , which is trivially true and just swaps the pair. The relation holds for any order.
The Euclidean algorithm can fail to terminate for very large inputs
False — the second number strictly shrinks each step () and stays , so it must hit after finitely many steps no matter how large the start.
for every positive integer
True — every number divides (since ), so the largest divisor shared by and is just the largest divisor of , which is itself. This is the algorithm's stopping value.
The last remainder computed by the algorithm is the GCD
False — the last non-zero remainder is the GCD. The very last remainder is , which is the signal to stop, not the answer.
If the algorithm does no work, since they share nothing
False — coprime pairs can take the most steps (e.g. consecutive Fibonacci numbers like ). "Sharing nothing but 1" still requires grinding the numbers down to reveal it.
Prime factorization and the Euclidean algorithm always give the same GCD
True — they compute the same quantity by different routes; only their speed differs. Euclid avoids factoring, which is why it scales to huge numbers.
Swapping the inputs, vs , can change the number of steps taken
True (essentially) — if you feed the smaller number first, the algorithm spends one bonus step just swapping them, then proceeds identically. The final GCD is unchanged.
Spot the error
": , and since is even, the GCD is ."
Wrong — you stopped too early. A non-zero remainder means continue: recurse on . The remainder being even (or anything) is irrelevant; only reaching remainder ends the process.
"Since , the GCD is the quotient ."
Wrong — is how many times fits into and gets thrown away. The GCD lives in the remainder chain; it is the last non-zero , never the quotient.
" can be negative when , so I must sort inputs first."
Wrong — for , gives remainder , a valid value in . The remainder is defined to be non-negative and less than ; no sorting needed.
"To speed things up I replaced with (one subtraction)."
Not an error in correctness but in efficiency — subtracting one at a time is the slow ancestor of Euclid. Using the full remainder () does all those subtractions at once, giving the fast behaviour.
"The algorithm output , so the GCD is ."
Wrong — when becomes the answer is the other variable , not . Reading off the zero itself is confusing the stopping flag with the result.
" so the algorithm handles it fine."
is a genuine edge case: every integer divides , so there is no greatest common divisor — it's conventionally defined as . The algorithm returns , but you should know it's a definition, not a computed maximum.
Why questions
Why must any common divisor of and also divide ?
Because , and a divisor of both and divides their difference. This inheritance is exactly why swapping to loses no common divisors.
Why does the set of common divisors stay identical at every step, not just the maximum?
The lemma shows divisibility flows both directions ( and ), so the full common-divisor set is preserved — hence its maximum, the GCD, is too.
Why is the worst case built from Fibonacci numbers?
The slowest shrinkage happens when every quotient is the smallest possible, , so . That recurrence is the Fibonacci rule, so consecutive Fibonacci numbers maximise the step count for their size.
Why do cryptographers prefer Euclid over factorization for finding a GCD?
Euclid runs in time proportional to the number of digits (polynomial), while factoring large numbers is believed to be exponentially hard — the whole security of RSA leans on that gap.
Why does the division algorithm deserve to be called the "engine" here?
Every single step is one application of the division algorithm; producing with is both what shrinks the problem and what guarantees termination.
Why can the Euclidean algorithm find a GCD without ever knowing the prime factors?
It only ever uses the relationship between differences and divisors, never the numbers' internal structure. The prime factorisation exists but is never needed — Euclid sidesteps it entirely.
Edge cases
What does the algorithm do when exactly (first remainder is )?
It stops immediately with as the GCD — e.g. in a single step, because already divides .
What is and how many steps does it take?
It equals , found in one step: , so it stops instantly. A number's largest self-shared divisor is itself.
What happens if one input is ?
always, because divides everything and nothing bigger divides . The remainder ends it in one step.
Can the GCD ever exceed the smaller of the two inputs?
No — a common divisor must divide the smaller number, so it cannot be larger than it. Equality happens exactly when the smaller number divides the larger.
How does the algorithm handle negative inputs like ?
Divisibility ignores sign, so ; in practice you take absolute values first, since the GCD is conventionally taken as positive.
Is still well-defined the moment we reach — have we "lost" information?
No information lost — every earlier step preserved the common-divisor set, so is genuinely the GCD of the original pair. The chain of equal GCDs connects the start to the finish.
Recall One-line self-test
Cover every answer above. If you can state the reason (not just the verdict) for at least 20 of these, you've internalised the traps. The recurring theme: stop at , read ; the GCD lives in the remainder chain, never the quotient.
Connections
- 2.5.7-euclidean-algorithm-gcd-computation — the parent this bank interrogates
- 2.5.01-divisibility-and-division-algorithm — the engine behind every step
- 2.5.03-fundamental-theorem-of-arithmetic — the factorisation Euclid deliberately avoids
- 2.5.08-extended-euclidean-algorithm — extends this to find Bézout coefficients
- 2.5.10-bezouts-identity — the payoff
- 1.4.09-fibonacci-sequence — the worst-case input family
- 3.2.04-rsa-encryption — why the speed gap over factoring matters