Homepage › Solution manuals › David S. Dummit › Abstract Algebra › Exercise 0.3.15 (Inverse of $a$ mod $n$)
Exercise 0.3.15 (Inverse of $a$ mod $n$)
For each of the following pairs of integers and , show that is relatively prime to and determine the multiplicative inverse of in .
- (a)
- (b)
- (c)
- .
- (d)
Answers
Proof. We use the Python program “bezout” given in Exercise 0.2.1.
def bezout(a,b): """input : integers (a,b) output : (x,y,d), (x,y) solution of ax+by =d, d = gcd(a,b) """ sgn_a = 1 if a >= 0 else -1 sgn_b = 1 if b >= 0 else -1 (r0, r1)=(abs(a), abs(b)) (u0, v0) = (1, 0) (u1, v1) = (0, 1) while r1 != 0: q = r0 // r1 (r2, u2, v2) = (r0 - q * r1, u0 - q * u1, v0 - q * v1) (r0, r1) = (r1, r2) (u0, u1) = (u1, u2) (v0, v1) = (v1, v2) x , y, d = sgn_a * u0, sgn_b * v0, r0 if x <= 0: x, y = x + abs(b), y - sgn_b * a return x, y, d
- (a)
-
In [1]: from numtheory import bezout In [2]: bezout(13, 20) Out[2]: (17, -11, 1)So in .
(verification: .)
- (b)
-
In [3]: bezout(69, 89) Out[3]: (40, -31, 1)So in .
- (c)
-
In [4]: bezout(1891,3797) Out[4]: (253, -126, 1)So in .
- (d)
-
In [5]: bezout(6003722857,77695236973) Out[5]: (77695236753, -6003722840, 1)So in .