Greatest Common Divisor
For two integers
When evaluating greatest common divisor between
Obviously there's
Euclidean algorithm
All of us have learned how to calculate the greatest common
divisor of two integers in our elementary school. And long
time ago the greek mathematician Euclid has invented an
algorithm to calculate the greatest common divisor of two
integers
- If
then we return and vice versa, otherwise start with where are integers to calculate greatest common divisor. - Calculate
, substitute . - Repeat step 2 until
, then is the greatest common divisor evaluated.
Proof
When the input integers are the same, then the integers' value itself is the greatest common divisor and could be evaluated by the algorithm above, trivially. Things also holds when either of them is zero. So let's just focus on the case of evaluating two different non-zero integers.
If the first step encounters that
Define
If the algorithm terminates at
Since
Complexity
To analyze the complexity of the algorithm, let's denote
the
Assume it takes
Intuitively, it is the algorithm's worst case that
The eigen matrix is denoted as
Least common multiple
Just like the way we define greatest common divisor, we
define the least common multiple
Obviously, a number to be divisible by both
Proof by construction
To be divisible by both
As we know
This shows us the relationship between products of two numbers, their greatest common divisor, and their least common multiple. And the least common multiple can be evaluated by evaluating the greatest common divisor, using the Euclidean algorithm we've described above.
Proof by prime factorization
If you feels like the proof above is not sound enough, there's
an alternative proof done by prime factorizing
Where
And since
Linear Diophantine equations
Structure of solutions
A linear Diophantine equation is an equation in the form
of
Let's do congruence modulo-
In the text above, we've analyzed that the Euclidean
algorithm is fundamentally a method in finding some linear
combination of
So
On the other hand, for another solution
To find the solution of
Finally, the structure of solution of linear Diophantine
equation
The equation in the form of
Extended Euclidean algorithm
The objective is simple, to recover Bezout's coefficients during the process of Euclidean algorithm. The analysis is clear, it is just some consecutive linear transform shown in the complexity analysis of Euclid algorithm. All we need to do is to take a deeper look at:
Obviously,
Given the matrix of step
Let's substitute
Besides finding the Bezout's coefficients, we've also
solved the equation
The key to the proof is hideous to some extent, which is
embedded in the determinants of the matrices. Each matrix
of
It has effectively found an integral solution of linear
Diophantine equation
In the meantime,
This should be sufficient for implementing the extended Euclidean algorithm. The algorithm should yield the greatest common divisor, the Bezout's coefficients, and the quotients after dividing the greatest common divisor.
Chinese remainder theorem
The Sunzi Suanjing has stated a problem that: there're some objects whose number is unknown, counting them 3 by 3 will have 2 remained, counting them 5 by 5 will 3 remained, and counting them 7 by 7 will have 2 remained, so how many objects are there?
The problem could be formalized as a linear congruences:
Let's start with the case of only two rows of congruences to solve. Obviously they are equivalent to system of linear Diophantine equations that:
Subtract them and move the terms so that:
This is a linear Diophantine equation about
And when
The analysis on linear congruences with two rows shows us
that
For the case of more rows of linear congruences, by
collapsing the first two rows iteratively you will finally
reach a point that all linear congruences are collapsed
into a single row of congruence. To ensure the collapsed
one and the original ones are equivalent,
Let's conclude it by solving the problem from Sunzi Suanjing, first write it as linear congruents:
For the first two rows, by Bezout's identity
Conclusion
Even the concept of greatest common divisor which most of us have learned in elementary school, has profound properties imbued, and itself solely can be used to solve linear Diophantine equations, to a complete extent.
Mastering number theory will certainly aid us a lot in the study of group theory and even harder algebra. But this requires us to comprehend and view mathematical structures in an interconnected manner.
- Don't panic or be matrix-phobic, some of you might be astonished about using linear algebra in such a kind of elementary school stuff, but soon you will see the charm of matrix not only on analyzing the complexity, but also in number theory proof. [return]
- In fact, usually a very large number will be taken into calculation. So the division's cost must be taken into consideration, which is also logarithmic. So strictly speaking, the total complexity will be
instead. [return] - This is also an important application of Bezout's identity, if you've found integers
such that , then each combination of will be coprime. [return]