Numbers: Integers
Greatest common divisor and least common multiple
minimum and maximum
If #a# and #b# are two real numbers, we can compare them. We write
#\min(a,b)# for the minimum (the smallest) of #a# and #b#, and
#\max(a,b)# for the maximum (the biggest) of #a# and #b#.
For example:
- #\max(3,8)=8# and #\max(-3,-8)=-3#, while
- #\min(3,8)=3# and #\min(-3,-8)=-8#.
gcd and lcm
The greatest common divisor of two integers #a# and #b# is the largest natural number that divides both #a# as #b#. This number is written as #\gcd(a,b)# (because the abbreviation greatest common divisor).
The least common multiple of two natural numbers #a# and #b# is the smallest natural number which is a multiple of both #a# and #b#. This number is written as #{\rm lcm}(a,b)# (because the abreviation least common multiple).
Examples:
\[ \begin{array}{rclcrcl}\gcd(2,3)&=&1&\phantom{xxxxx}&{\rm lcm}(2,3) &=&6\\ \gcd(4,6)&=&2&\phantom{xxxxx}&{\rm lcm}(4,6) &=&12\\ \gcd(4,4)&=&4&\phantom{xxxxx}&{\rm lcm}(4,4) &=&4\end {array}\]
Let #a# and #b# be natural numbers. There are always numbers that divide both #a# and #b#, because #1# is such a number.
Any number that divides #a# and #b#, is less than or equal to #\min(a,b)#. Therefore, there is a greatest common divisor, and \[1\le \gcd(a,b)\le\min(a,b)\tiny.\]
There is always a number that is a multiple of both of #a# and #b#, being #a\times b#. On the other hand such a common multiple is greater than or equal to #\max(a,b)#. Therefore, there is a least common multiple and \[\max(a,b)\le {\rm lcm}(a,b)\le a\times b\tiny.\]
There is also a greatest common divisor and a least common multiple of more than two numbers. For example, \[ \begin{array}{rclcrcl}\gcd(2,3,6)&=&1&\phantom{xxxxx}&{\rm lcm}(2,3,6) &=&6\\ \gcd(2,4,6)&=&2&\phantom{xxxxx}&{\rm lcm}(2,4,6) &=&12\\ \gcd(4,6,8)&=&2&\phantom{xxxxx}&{\rm lcm}(4,6,8) &=&24\end {array}\] In general, we have, for three natural numbers #a#, #b#, #c#:
\[ \gcd(a,b,c)=\gcd\left(\gcd(a,b),c\right)\tiny.\]
We define the greatest common divisor (gcd) and least common multiple (lcm) for all integers by means of the condition that the outcomes do not depend on signs.
gcd and lcm for aribtrary integers
Let #a# and #b# be integers.
- #\gcd(a,0) =\gcd(0, a)=a# and #{\rm lcm}(a,0)={\rm lcm}(0,a)=0#
- #\gcd(a,b)=\gcd(-a,b)=\gcd(a,-b)=\gcd(-a,-b)#
- #{\rm lcm}(a,b)={\rm lcm}(-a,b)={\rm lcm}(a,-b)={\rm lcm}(-a,-b)#
The definition #\gcd(a,0)=0# satisfies the definition, because #a# divides both #0# and itself and is the largest natural number having that property.
All equalities in the last two lines of the definition indicate that for the definition of #\gcd# and #\rm lcm# the sign does not matter.
The values of #\gcd# and #\rm lcm# are never negative.
Example: #\gcd(15,-20)=\gcd(15,20)=5#.
The highest power of a prime#p# dividing #a# is the biggest number that divides #a# and is of the form #p^c# for some non-negative integer #c#. These powers can be used to determine the greatest common divisor of two integers.
gcd rules
Let #a# be a natural number, and #b# a non-negative integer.
- If #m# is a natural number that divides #a# and #b#, then #\gcd( a, b) = m\times\gcd\left(\frac{a}{m},\frac{b}{m}\right)# holds.
- #\gcd(a,b) = \gcd(r,b)#, where #r# is the remainder after division of #a# on #b#.
- #\gcd(a,b)# is the product of the highest powers of a prime number that divide both #a# and #b#.
- #{\rm lcm}(a,b)# is the product of the highest powers of a prime number that divide #a# or #b# (or both).
- #{\rm lcm}(a,b) = \frac{a\times b}{\gcd(a,b)}#.
The proof will be omitted, but we note that all the statements follow from rules 3 and 4.
Some examples:
- #\gcd(42,28)=\gcd(7\times 6,7\times4) =7\times\gcd(6,4)= 14#.
- The number #14# is the remainder of the division of #42# on #28#, so #\gcd(42,28) = \gcd(14,28)#.
- #\gcd(42,28)=\gcd(2\times3\times7,2^2\times7)=2\times7=14#, as #2# is the highest power of #2# dividing both #42# and #28#, similarly for #7#, and #1# is the highest power of #3# dividing both #42# and #28#.
- #{\rm lcm}(42,28)={\rm lcm}(2\times3\times7,2^2\times7)=2^2\times3\times7=84#, as #2^2# is the highest power of #2# dividing #42# or #28#, and similarly for #3# and #7#.
- #{\rm lcm}(42,28) = 84=42\times 2=\frac{42\times 28}{14}=\frac{42\times 28}{\gcd(42,28)}#.
When the factorization of the numbers #a# and #b# is known, rules 3 and 4 work very quickly to determine the gcd. If this is not the case, then rule 2 will help, as the following algorithm shows.
An algorithm is a series of steps that must be performed one after the other to get to a determined prescribed result from a certain type of data. In presenting an algorithm, first we specify what type of data the algorithm starts of with, the import, and what the algorithm produces, the output. Next, we formulate the steps that make up the algorithm.
The Euclidean algorithm
input: a pair of #\rv{a,b}# of a non-negative integer #a# and a natural number #b#
output: #\gcd(a,b)#
- #\rv{r,s}= \rv{\max(a,b),\min(a,b)}#
- keep replacing #\rv{r,s}# by #\rv{s,t}#, where #t# is the remainder of the division of #r# on #s#, until #s=0#
- execute #r#
For the remainder #t# in step 2, the formula #t=r-\left\lfloor \frac{r}{s}\right\rfloor\times s# applies.
Each instance of the pair #\rv{r,s}# satisfies #\gcd(r,s)=\gcd(a,b)#:
1. In the beginning because #\rv{r,s}# is equal to #\rv{a,b}# or #\rv{b,a}#,
2. At the end of each step w, because of gcd-rule 2.
When we are done with step 2, then #s=0# holds and #\gcd(a,b)=\gcd(r,0)=r# follows from this. Hence, the output indeed provides #\gcd(a,b)#.
For, by application of the Euclidean algorithm, we find
\[ \begin{array}{rclcl} \gcd(62,322)&=&\gcd(322,62)&\phantom{}&\color{blue}{\text{biggest one up front}}\\
&=& \gcd(62,322-\left\lfloor\frac{ 322}{62}\right\rfloor \cdot {62})= \gcd(62,12)&&\color{blue}{\text{iteration 1}}\\
&=& \gcd(12,62-\left\lfloor \frac{62}{12}\right\rfloor\cdot 12)= \gcd(12,2)&&\color{blue}{\text{iteration 2}} \\ &=& \gcd(2,12-\left\lfloor \frac{12}{2}\right\rfloor\cdot 2)= \gcd(2,0)&&\color{blue}{\text{iteration 3}}\\ &=&2\tiny.&&\color{blue}{\gcd(a,0)=a}\end {array} \]
Or visit omptest.org if jou are taking an OMPT exam.