taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Exercise · Volume 1 · 1.1-4

Exercise 1.1-4

not stated yet in Lean solution written

Rating16
KindK3, find a value: compute a number, a set or a closed form from the written solution
SectionSection 1.1 of Volume 1. Companion chapter: Algorithms

The task

Find gcd⁡(2166,6099)\gcd(2166, 6099) with Euclid's algorithm.

The exact wording is in your copy of the book.

Hints

Open one hint at a time. Try the exercise again after each.

Hint 1

Start with m=2166m = 2166 and n=6099n = 6099 in Algorithm E. The first pass swaps the numbers.

Hint 2

At each pass divide the larger by the smaller and keep the remainder.

Solution

Show the solution

The passes of Algorithm E, with the quotient and remainder of step E1, are in the table.

mm nn quotient rr
2166 6099 0 2166
6099 2166 2 1767
2166 1767 1 399
1767 399 4 171
399 171 2 57
171 57 3 0

In the last pass r=0r = 0, so the answer is the value of nn then, which is 5757.

Check

Factor the numbers: 2166=2⋅3⋅1922166 = 2 \cdot 3 \cdot 19^2 and 6099=3⋅19⋅1076099 = 3 \cdot 19 \cdot 107. The common part is 3⋅19=573 \cdot 19 = 57. Also 2166=38⋅572166 = 38 \cdot 57 and 6099=107⋅576099 = 107 \cdot 57, and 3838 and 107107 have no common factor.

Remarks

Algorithm E does 6 divisions here, and the first one is the wasted swap. The numbers 3838 and 107107 are the quotients m/gcd⁡m/\gcd and n/gcd⁡n/\gcd, and Exercise 1.1-6 studies how many divisions a typical input needs.

This solution is checked, and a person has not reviewed it yet. The source.

In Lean

not stated yet The exercise is not stated in Lean yet.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.