Greatest Common Divisor
Last updated
Last updated
The Greatest Common Divisor (GCD), sometimes known as the highest common factor, is the largest number which divides two positive integers (a,b). For
a = 12, b = 8
we can calculate the divisors of a:{1,2,3,4,6,12}
and the divisors of b:{1,2,4,8}
. Comparing these two, we see thatgcd(a,b) = 4
. Now imagine we takea = 11, b = 17
. Botha
andb
are prime numbers. As a prime number has only itself and1
as divisors,gcd(a,b) = 1
. We say that for any two integersa,b
, ifgcd(a,b) = 1
thena
andb
are coprime integers. Ifa
andb
are prime, they are also coprime. Ifa
is prime andb < a
thena
andb
are coprime. Think about the case fora
prime andb > a
, why are these not necessarily coprime? There are many tools to calculate the GCD of two integers, but for this task we recommend looking up . Try coding it up; it's only a couple of lines. Usea = 12, b = 8
to test it. Now calculategcd(a,b)
fora = 66528, b = 52920
and enter it below.
To answer the first quiz question, if b > a
and a
is prime, then it is possible that b
is a multiple of a
, so the GCD of these two numbers is a
and they are not coprime.
Let's take a look at Euclid's Algorithm
We are given two positive integers a
and b
, assume that a > b
Divide a / b
to get the remainder r
and if r = 0
, b
is the GCD of a, b
Else, replace a
with b
and b
with r
, then repeat
Though of course, if you're lazy you can use an online tool
1512