 is a prime and
 is a prime and  , then
, then  or
 or  .  Proving this is the key step in our proof of
Theorem 1.1.6.
.  Proving this is the key step in our proof of
Theorem 1.1.6.  
 
unless both
 and
 and  are 0
 in which case
 are 0
 in which case
 .
. ,
, 
 , and
for any
, and
for any  ,
, 
 .
.
If  , the greatest common divisor exists because if
, the greatest common divisor exists because if  then
then  , and there are only
, and there are only  positive integers
 positive integers  .
Similarly, the
.
Similarly, the  exists when
 exists when  .
.
 , since the other cases
are proved in a similar way. Suppose
, since the other cases
are proved in a similar way. Suppose  and
 and
   , so there exist integers
, so there exist integers  and
 and  such that
 such that  and
 and  .  Then
.  Then 
 , so
, so
   .  Thus
.  Thus 
 , since the set over
  which we are taking the max for
, since the set over
  which we are taking the max for  is a subset of the set
  for
 is a subset of the set
  for 
 .  The same argument with
.  The same argument with  replaced by
 replaced by  and
  and  replaced by
 replaced by  , shows that
, shows that 
 , which proves that
, which proves that 
 .
.
  
Assume for the moment that we have already proved
Theorem 1.1.6.  A natural (and naive!)  way to compute
 is to factor
 is to factor  and
 and  as a product of primes using
Theorem 1.1.6; then the prime factorization of
 as a product of primes using
Theorem 1.1.6; then the prime factorization of
 can read off from that of
 can read off from that of  and
 and  .  For example, if
.  For example, if
 and
 and  , then
, then 
 and
 and 
 , so
, so 
 .  It turns out that the
greatest common divisor of two integers, even huge numbers (millions
of digits), is surprisingly easy to compute using
Algorithm 1.1.13 below, which computes
.  It turns out that the
greatest common divisor of two integers, even huge numbers (millions
of digits), is surprisingly easy to compute using
Algorithm 1.1.13 below, which computes  without
factoring
 without
factoring  or
 or  .
.  
To motivate Algorithm 1.1.13, we compute 
 in
a different way.  First, we recall a helpful fact.
 in
a different way.  First, we recall a helpful fact.
 and
 and  are integers with
 are integers with  .  Then there
  exists unique integers
.  Then there
  exists unique integers  and
 and  such that
 such that 
 and
 and 
 .
. and
 and  are positive (we leave
  the general case to the reader). Let
 are positive (we leave
  the general case to the reader). Let  be the set of all
  nonnegative integers
 be the set of all
  nonnegative integers  such that
 such that  is nonnegative.  Then
 is nonnegative.  Then  is nonempty because
  is nonempty because  and
 and  is bounded because
 is bounded because  for
  all
 for
  all  .  Let
.  Let  be the largest element of
 be the largest element of  .  Then
.  Then 
 , otherwise
, otherwise  would also be in
 would also be in  .  Thus
.  Thus  and
 and  satisfy
  the existence conclusion.
 satisfy
  the existence conclusion.
To prove uniqueness, suppose for the sake of contradiction that  and
  and  also satisfy the conclusion but that
 also satisfy the conclusion but that  . Then
. Then
   since
 since 
 , so
, so  and we can write
 and we can write
   for some
 for some  .  But then
.  But then 
 since
 since  , a contradiction.
, a contradiction.
  
For us an algorithm is a finite sequence of instructions that can be followed to perform a specific task, such as a sequence of instructions in a computer program, which must terminate on any valid input. The word ``algorithm'' is sometimes used more loosely (and sometimes more precisely) than defined here, but this definition will suffice for us.
 and
 and  are integers with
 are integers with  . This algorithm
computes integers
. This algorithm
computes integers  and
 and  such that
 such that 
 and
 and 
 .   We will not describe the actual steps of this algorithm,
since it is just the familiar long division algorithm.
.   We will not describe the actual steps of this algorithm,
since it is just the familiar long division algorithm.
We use the division algorithm repeatedly to compute
 .  Dividing
.  Dividing  by
 by  we find that
 we find that
 
so
 and
 and  .
Notice that if a natural number
.
Notice that if a natural number  divides both
 divides both  and
 and  ,
then
,
then  divides their difference
 divides their difference  and
 and  still divides
 still divides  .
On the other hand, if
.
On the other hand, if  divides both
 divides both  and
 and  , then it has
to divide their sum
, then it has
to divide their sum  as well!  We have made progress:
 as well!  We have made progress:
 
This equality also follows by repeated application of Lemma 1.1.9. Repeating, we have
 
so
 .
Keep going:
.
Keep going:
|  |  | |
|  |  | |
|  |  | 
 , which is
, which is  because
 
because  .  Thus
.  Thus
 
Aside from some tedious arithmetic, that computation was systematic, and it was not necessary to factor any integers (which is something we do not know how to do quickly if the numbers involved have hundreds of digits).
 , this algorithm computes
, this algorithm computes  .
.
 ] We have
] We have 
 ,
so we may replace
,
so we may replace  and
 and  by their absolute value and hence
assume
 by their absolute value and hence
assume 
 .  If
.  If  output
 output  and
terminate.  Swapping if necessary we assume
 and
terminate.  Swapping if necessary we assume  .
.  
 , with
, with  and
 and 
 .
.  
 then
 then  , so we output
, so we output  and terminate.
 and terminate.
 and
 and 
 , then go to 
step 2.
, then go to 
step 2.
 so the gcd does not
change in step 4.  
Since the remainders form a decreasing sequence of nonnegative
integers, the algorithm terminates.
 so the gcd does not
change in step 4.  
Since the remainders form a decreasing sequence of nonnegative
integers, the algorithm terminates.
  
 and
 and  .
.
|  |  |  | |
|  |  |  | 
sage: gcd(97,100) 1 sage: gcd(97 * 10^15, 19^20 * 97^2) 97
 and note that at every step the
  equation is the equation from Euclid's algorithm for
 and note that at every step the
  equation is the equation from Euclid's algorithm for  but
  multiplied through by
 but
  multiplied through by  .  For simplicity, assume that both
.  For simplicity, assume that both  and
  and  are positive.  We will prove the lemma by induction on
 are positive.  We will prove the lemma by induction on
   . The statement is true in the base case when
. The statement is true in the base case when  ,
  since then
,
  since then  .  Now assume
.  Now assume  are arbitrary with
 are arbitrary with  .
  Let
.
  Let  and
 and  be such that
 be such that 
 and
 and 
 .  Then by
  Lemmas 1.1.9-1.1.10, we have
.  Then by
  Lemmas 1.1.9-1.1.10, we have 
 .  Multiplying
.  Multiplying  by
 by  we see that
 we see that 
 , so
, so 
 .  Then
.  Then
  
 
so by induction
 .  Since
.  Since 
 ,
  this proves the lemma.
,
  this proves the lemma.
  
At this point it would be natural to formally analyze the complexity of Algorithm 1.1.13. We will not do this, because the main reason we introduced Algorithm 1.1.13 is that it will allow us to prove Theorem 1.1.6, and we have not chosen to formally analyze the complexity of the other algorithms in this book. For an extensive analysis of the complexity of Algorithm 1.1.13, see [#!knuth2!#, §4.5.3].
With Algorithm 1.1.13, we can prove that if a prime divides the product of two numbers, then it has got to divide one of them. This result is the key to proving that prime factorization is unique.
You might think this theorem is ``intuitively obvious'', but that might be because the fundamental theorem of arithmetic (Theorem 1.1.6) is deeply ingrained in your intuition. Yet Theorem 1.1.19 will be needed in our proof of the fundamental theorem of arithmetic.
 we are done.  If
 we are done.  If  then
 then 
 , since
  only
, since
  only  and
 and  divide
 divide  .  By Lemma 1.1.17,
.  By Lemma 1.1.17,
  
 . Since
. Since  and, by hypothesis,
 and, by hypothesis,  ,
  it follows from Lemma 1.1.17 that
,
  it follows from Lemma 1.1.17 that
  
 
 
William 2007-06-01