Euclidean Algorithm
輾轉
(
gcd(n, 0) = 0, if n > 0
gcd(m, n) = gcd(n, m mod n), if m > n
m nr
0
= m, r
1
= n
r
0
= q
1
r
1
+ r
2
, 0 r
2
< r
1
r
1
= q
1
r
2
+ r
3
, 0 r
3
< r
2
.
.
.
r
n2
= q
n1
r
n1
+ r
n
, 0 r
n
< r
n1
r
n1
= q
n
r
n
gcd(m, n) = gcd(r
0
, r
1
) = gcd(r
1
, r
2
) = · · · = gcd(r
n2
, r
n1
) =
gcd(r
n1
, r
n
) = gcd(r
n
, 0) = r
n
94
:
Find all of the possible solutions of 250x + 111y = 7, where both x
and y are integers.
Ans.
250 = 2 × 111 + 28
111 = 3 × 28 + 27
28 = 1 × 27 + 1
1 = 28 27
1 = 28 (111 3 × 28)
1 = (1) × 111 + 4 × 28
1 = (1) × 111 + 4 × (250 2 × 111)
1 = (9) × 111 + 4 × 250
()
1 = (9 + 250k) × 111 + (4 111k) × 250, k Z
7
7 = 7(9 + 250k) × 111 + 7(4 111k) × 250, k Z
x = 7(4 111k), y = 7(9 + 250k), k Z