Exercise 1.3

Calculate ( 187 , 221 ) , ( 6188 , 4709 ) , ( 314 , 159 ) .

Answers

Proof. With direct instructions in Python, we obtain :

>>> a, b = 187,  221
>>> print("q = ",a//b); a, b = b, a%b; print(a,b)
q =  0
221 187
>>> print("q = ",a // b); a, b = b, a%b; print(a,b)
q =  1
187 34
>>> print("q = ",a // b); a, b = b, a%b; print(a,b)
q =  5
34 17
>>> print("q = ",a // b); a,b = b, a%b; print(a,b)
q =  2
17 0

This gives the equalities

187 = 0 × 221 + 187 221 = 1 × 187 + 34 187 = 5 × 34 + 17 34 = 2 × 17 + 0

So 187 221 = 17 .

With the same instructions, we obtain

6188 = 1 × 4709 + 1479 4709 = 3 × 1479 + 272 1479 = 5 × 272 + 119 272 = 2 × 119 + 34 119 = 3 × 34 + 17 34 = 2 × 17 + 0

6188 4709 = 17 .

Finally

314 = 1 × 159 + 155 159 = 1 × 155 + 4 155 = 38 × 4 + 3 4 = 1 × 3 + 1 3 = 3 × 1 + 0

314 159 = 1 .

The Python script which gives the gcd is very concise :

def gcd(a,b):
    a, b = abs(a), abs(b)
    while b != 0:
        a, b = b, a % b
    return a

User profile picture
2022-07-19 00:00
Comments