Factoring
Every integer can be represented as the product of primes: there exists a positive integer and primes such that .
Existence
What happens if is prime?
In this case, and . So the phrase "product of primes" should not be taken too literally: in this case there is only one (prime) number in the "product" and the product is equal to this number. (One could even allow by considering an "empty product" with no factors that is equal to , but we will not go that far.)
Note also that we do not require the to all be distinct: for example,
Prove the Theorem
Let us look at this statement from the algorithmic point of view: given some , how can we find a prime decomposition (existence of which we want to prove)?
If is prime, we already know that this decomposition consists of only. What if is composite (not prime)?
By definition then, for some where . How can we then find the decomposition of ?
It is easy: just combine the decompositions of and , forming a long product from the two shorter ones. Both and are smaller that , so we may assume (by induction in our proof, or a recursive call in our algorithm) that for and the decompositions exist and can be found.
# Finds the minimal divisor>1 of the given integer m>1
def min_divisor(m):
for d in range(2, m + 1):
if m % d == 0:
return d
# optimization:
if d * d > m:
return m
def is_prime(m):
return m == min_divisor(m)
def factoring(m):
if is_prime(m):
return [m]
else:
divisor = min_divisor(m)
factors = factoring(m // divisor)
factors.append(divisor)
return factors
The numbers of the form were considered long ago by Pierre Fermat (1607--1665, Wikipedia), famous for the Last Fermat theorem; we will see the other result of him later in this chapter. He noticed that are all primes and conjectured that all subsequent numbers are also prime.
Only later Leonhard Euler (1707--1783,Wikipedia) discovered the factorization of in 1732, and more than a century after that was needed to find the factorization of . Now our simple program gives these factorization in seconds. (But do not forget two optimization lines, otherwise it would take much longer.)
For the next Fermat numbers one should use more advanced factorization algorithms. There is a module sympy in python that provides function factorint that factors and in minutes, but Fermat numbers grow really fast (and only few more factorizations are known, even if we use the most advanced factorization tools).
Unique Factoring
Decomposition of an integer into a product of prime factors is essentially unique. The word essentially here means that we ignore the ordering of the factors: they can be permuted in any way and we still get the same decomposition. For example,
First, let us note that we can group identical factors in the decomposition. In this we get a product of the form
Here all are different, and all are positive integers (the number of occurrences of in the factorization).
The number is called the multiplicity of a prime in . If does not appear in the decomposition, we say that the multiplicity of in equals zero. (This sounds natural since we may add fictional term in the factoring.)
Divisors and Multiplicity
Complete the statement: an integer is a divisor of an integer if and only if the multiplicity of for every prime .
The last part can be filled as follows: if the multiplicity of in does not exceed the multiplicity of in , for every prime . Indeed, imagine that is a divisor of , i.e., that for some . Then the (unique) factorization of is obtained by concatenating the factorizations of and . Therefore, the multiplicity of every prime in is the sum of its multiplicities in and , and is greater or equal than the multiplicity of in .
On the other hand, if every prime appears in the factorization of at least as many times as for , then we can add missing factors to to obtain . If is the product of these missing factors, then , so divides .
Problem
Consider all the positive divisors of . How many of them do exist (including trivial divisiors and )?
As the previous problem shows, all the divisors have the form where and . For we get , for and we get . We may list all of them systematically:
We do not need to write them all explicitly; we have only to count them. Each of five powers of (i.e., ) is combined with four powers of (i.e., ), so we get combinations that lead (as we know) to divisors.
Question : How many positive divisors has ?
See answer ▼
Answer : 3696
Question : What is the minimal positive number that has exactly divisors?
See answer ▼
Answer : 144
We must choose the smallest prime numbers and large numbers for this.