High School Modules > Algebra by Gregory A. Moore
GCD & LCM
An examination of the concept of the gcd and lcm . We explore the concept, examine a method to compute these values, use a quick Maple way of computing them, and examine an interesting property of gcd's and lcm's.
[Directions : Execute the Code Resource section first. Although there will be no output immediately, these definitions are used later in this worksheet.]
0. Code
| > | restart; |
| > | FactorTable := proc( n, m ) local N, M, P, i,j,k, A, p ; print( n = ifactor(n) ); print( m = ifactor(m) ); N := numtheory[factorset](n); M := numtheory[factorset](m); P := N union M; p := nops(P); #for k from 1 to nops(M) do print( M[k]); od; A := array( [seq( [ seq( ` `, j = 1..p+2 ) ], i = 1..2+2 ) ]); for j from 1 to p do A[1,j+2] := P[j]; od; for j from 1 to p do A[2,j+2] := `__`; od; A[3,1] := n; A[4,1] := m; A[3,2] := `|`; A[4,2] := `|`; A[1,1] := `primes =`; for k from 1 to p do for i from 0 by 1 while (irem(n,P[k]^i)=0) do end do; A[3, k + 2] := ifactor(P[k]^(i-1)); od; for k from 1 to p do for i from 0 by 1 while (irem(m,P[k]^i)=0) do end do; A[4, k + 2] := ifactor(P[k]^(i-1)); od; print(A); end proc: |
| > | GCDTable := proc( n, m ) local N, M, P, i,j,k, A, p ; N := numtheory[factorset](n); M := numtheory[factorset](m); P := N union M; p := nops(P); #for k from 1 to nops(M) do print( M[k]); od; A := array( [seq( [ seq( ` `, j = 1..p+3 ) ], i = 1..2+4 ) ]); for j from 1 to p do A[1,j+2] := P[j]; od; for j from 1 to p do A[2,j+2] := `__`; od; for j from 1 to p do A[5,j+2] := `__`; od; A[3,1] := n; A[4,1] := m; A[3,2] := `|`; A[4,2] := `|`; A[1,1] := `primes =`; #______Row with 1st factorization_________ for k from 1 to p do for i from 0 by 1 while (irem(n,P[k]^i)=0) do end do; A[3, k + 2] := ifactor(P[k]^(i-1)); od; #______Row with 2nd factorization_________ for k from 1 to p do for i from 0 by 1 while (irem(m,P[k]^i)=0) do end do; A[4, k + 2] := ifactor(P[k]^(i-1)); od; #______Last row with GCD factorization_________ for k from 1 to p do for i from 0 by 1 while (irem(m,P[k]^i)=0) do end do; A[6, k + 2] := ifactor( min( expand(A[3,k+2]),expand(A[4,k+2]))); od; A[6,1] := `GCD =`; A[6, p + 3] := 1; for k from 1 to p do A[6, p + 3] := expand(A[6, p+3]* A[6,k+2]); od; A[6, p + 3] := cat(`= `, A[6, p + 3]); print(A); end proc: |
| > | LCMTable := proc( n, m ) local N, M, P, i,j,k, A, p ; N := numtheory[factorset](n); M := numtheory[factorset](m); P := N union M; p := nops(P); #for k from 1 to nops(M) do print( M[k]); od; A := array( [seq( [ seq( ` `, j = 1..p+3 ) ], i = 1..2+4 ) ]); for j from 1 to p do A[1,j+2] := P[j]; od; for j from 1 to p do A[2,j+2] := `__`; od; for j from 1 to p do A[5,j+2] := `__`; od; A[3,1] := n; A[4,1] := m; A[3,2] := `|`; A[4,2] := `|`; A[1,1] := `primes =`; for k from 1 to p do for i from 0 by 1 while (irem(n,P[k]^i)=0) do end do; A[3, k + 2] := ifactor(P[k]^(i-1)); od; for k from 1 to p do for i from 0 by 1 while (irem(m,P[k]^i)=0) do end do; A[4, k + 2] := ifactor(P[k]^(i-1)); od; for k from 1 to p do for i from 0 by 1 while (irem(m,P[k]^i)=0) do end do; A[6, k + 2] := ifactor( max( expand(A[3,k+2]), expand(A[4, k+2]))); od; A[6,1] := `LCM =`; A[6, p + 3] := 1; for k from 1 to p do A[6, p + 3] := expand(A[6, p+3]* A[6,k+2]); od; A[6, p + 3] := cat(`= `, A[6, p + 3]); print(A); end proc: |
| > | min_element := proc( S) local n, i, min; n := nops(S); min := S[1]; for i from 1 to n do if( min > S[i] ) then min := S[i]; fi; od; min; end proc: |
| > | max_element := proc( S) local n, i, max; n := nops(S); max := S[1]; for i from 1 to n do if( max < S[i] ) then max := S[i]; fi; od; max; end proc: |
| > | gcd_concept := proc(n, m) local N, M, Common; N := numtheory[divisors](n); print(cat(`\ndivisors of `,n, ` = `,convert(N , string))); M := numtheory[divisors](m); print(cat(`\ndivisors of `,m, ` = `,convert(M , string))); Common := % intersect %%: print( `\nCommon divisors` = Common); print( `\nGCD = maximum divisor ` = max_element( Common )); end proc: |
| > | lcm_concept := proc(n, m) local N, M, Common; N := {seq( n*k, k = 1..m)}; print(cat(`\nmultiples of `,n, ` = `)); print(cat(` `, convert(N , string)) ); M := {seq( m*k, k = 1..n)}; print(cat(`\nmultiples of `,m, ` = `)); print(cat(` `, convert(M , string)) ); Common := % intersect %%: print(`\nCommon multiples` = Common); print(`\nLCM = minimum multiple ` = min_element( Common )); end proc: |
1. Creating a Prime Factorization Table
Every positive integer (greater than one) can be factored into a product of primes.
| > | 24: % = ifactor(%); 90: % = ifactor(%); |
Given two numbers, we can create a table, by organizing this information. We write the original numbers along the left side, and list ALL of the primes available in either of the two numbers along the top. Then we fill in what power of the given prime is present in each number.
| > | FactorTable( 24, 90); |
Lets try some other examples.
| > | FactorTable( 20, 15); |
| > | FactorTable( 42,36); |
| > | FactorTable( 144, 196); |
| > | FactorTable( 15801075, 149232375); |
2. The Concept of the GCD
Each integer has a certain number of divisors - numbers which divide into the number evenly. If we make a list of the divisors of each number, then take the intersection of those two sets, we have a list of common factors. These common divisors are the only numbers which divide both of the two original numbers.
Now we if simply take the greatest of these common divisors, we have the gcd - the "greatest common divisor."
| > | gcd_concept( 18, 24); |
| > | gcd_concept( 25, 35); |
| > | gcd_concept( 144, 192); |
| > | gcd_concept( 45, 210); |
| > | gcd_concept( 120, 180); |
| > | gcd_concept( 17810275, 5686625); |
| > | gcd_concept( 300766484081591, 477666356354107); |
Notice that if there are no common prime factors, then the gcd is always 1.
| > | gcd_concept( 8, 9 ); |
| > | gcd_concept( 25,36); |
| > | gcd_concept( 144, 149); |
| > | gcd_concept( 96, 95); |
3. The Concept of the LCM
We can take multiples of any number. For example, the multiples of 6 are 6, 12, 18, 24, 36, 42, 48, 54, 60, 66, ....
There are an infinite number of multiples.
If we have two numbers, each has its own list of multiples. If we take the intersection of those two sets, we get the common multiples. The least of these is the LCM, or "least common multiple."
| > | lcm_concept( 4, 6); |
| > | lcm_concept( 8, 10); |
| > | lcm_concept( 18, 24); |
| > | lcm_concept( 48, 72); |
| > | lcm_concept( 105, 189); |
Note - that if there are no common prime factors, then the LCM is the product of the two numbers.
| > | lcm_concept( 5, 7); |
| > | lcm_concept( 24, 25); 25*24; |
| > | lcm_concept( 32, 30); 32*24; |
| > | lcm_concept( 125, 126); 125*126; |
| > | lcm_concept( 345, 198); 345 * 198; |
4. Finding the GCD from the Factorization Table
To find the the GCD of two numbers - the greatest common divisor - create a prime factorization table ... and ...
| > | FactorTable( 24, 28); |
... then take the MINIMUM of each column of primes. The product of these minimums is the GCD.
| > | GCDTable( 24, 28); |
Lets find the GCD of 15 and 20.
| > | GCDTable( 15, 20); |
| > | GCDTable( 80, 200); |
| > | GCDTable( 48, 72); |
| > | GCDTable( 105, 140); |
| > | GCDTable( 144, 192); |
| > | GCDTable( 2239245, 2626275); |
| > | GCDTable( 10983487, 11348973); |
5. Finding the LCM from the Factorization Table
To find the the LCM of two numbers - the greatest common multiple - create a prime factorization table ... and ...
| > | FactorTable( 24, 28); |
...this time...take the MAXIMUM of each column rather than the minimum.
| > | LCMTable( 18, 24); |
| > | LCMTable( 16, 24); |
| > | LCMTable( 25, 35); |
| > | LCMTable( 28, 49); |
| > | LCMTable( 108, 81); |
| > | LCMTable( 96, 72); |
| > | LCMTable( 80, 45); |
| > | LCMTable( 1734, 1581); |
| > |
6. Finding the GCD & LCM Using Maple
Maple can compute these very quickly and directly :
| > | gcd( 18, 24); lcm( 18, 24); |
Here is another
| > | gcd( 100, 120); lcm( 100, 120); |
Here is something interesting. This also works for algebraic expressions as well as numbers.
| > | gcd( 4*x^2, 6*x); lcm( 4*x^2, 6*x); |
| > | A := 24*(x^5)*(y^2); B := 36*(x^4)*(y^3); `gcd ` = gcd( A, B); `lcm ` = lcm( A, B); |
| > | A := (x-3)*(x+8); B := (x+5)*(x+8); `gcd ` = gcd( A, B); `lcm ` = lcm( A, B); |
| > | A := x^3+11*x^2+19*x+9; B := x^3+9*x^2-x-9; `gcd ` = factor( gcd( A, B )); `lcm ` = factor( lcm( A, B)); |
7. Product Relationship
Lets compare the product of two numbers to the product of their gcd and lcm.
| > | A := 24; B := 36; `gcd = ` = gcd(A, B); `lcm = ` =lcm(A, B); print(` `); `A*B = ` =A*B; `gcd * lcm ` =gcd(A, B)*lcm(A, B); |
Isn't that amazing? The two products are the same! Lets try some other examples to see if they work too.
| > | A := 64; B := 72; `gcd = ` = gcd(A, B); `lcm = ` =lcm(A, B); print(` `); `A*B = ` =A*B; `gcd * lcm ` =gcd(A, B)*lcm(A, B); |
| > | A := 105; B := 75; `gcd = ` = gcd(A, B); `lcm = ` =lcm(A, B); print(` `); `A*B = ` =A*B; `gcd * lcm ` =gcd(A, B)*lcm(A, B); |
| > | A := 2100; B := 750; `gcd = ` = gcd(A, B); `lcm = ` =lcm(A, B); print(` `); `A*B = ` =A*B; `gcd * lcm ` =gcd(A, B)*lcm(A, B); |
| > | A := 488; B := 160; `gcd = ` = gcd(A, B); `lcm = ` =lcm(A, B); print(` `); `A*B = ` =A*B; `gcd * lcm ` =gcd(A, B)*lcm(A, B); |
| > |
It appears there is a formula : A*B = gcd(A,B) * lcm(A*B). Can you prove it?
© 2002 Waterloo Maple Inc