Coprimality in Lowest Common Multiple
Suppose that we select arbitrarily a number of, say, integers, denoted by . If we obtain their lowest common multiple (LCM), and label it as , then take for each of the initial integers the corresponding number () such that multiplying by that number gives us the LCM, i.e. for each , an intriguing pattern starts to emerge: all the numbers are coprime, i.e. .
The following is an example code snippet that illustrates this phenomenon. This snippet generates a list of random integers between and , obtains their LCM, extract the factor for each of , where , from the LCM and calculate the greatest common divisor (GCD) of the 's.
Repeatedly running this code generates a different group of integers, but notice that the GCD obtained in the end is always 1.
The definitions of lcm_euclidean_general
and gcd_euclidean_general
in the snippet can be found in this note.
from random import randint
n, K = 4, 2000 # feel free to change the parameters here
test = [randint(0, K) for i in range(n)]
lcm = lcm_euclidean_general(*test)
smallest_k = tuple(map(lambda x: lcm // x, test))
print(gcd_euclidean_general(*smallest_k)) # 1
Why though?
To those who are familiar with the topic of coprime integers, this phenomenon should not come as a surprise. Nevertheless, a brief explanation of this fact will be presented here.
If we assume that the numbers , where are not coprime, or equivalently , and we call the GCD to be , then we can write where is an integer and . It follows that for each .
However, this also means that we can divide each of them throughout by and obtain for each . Note that because and , and is a constant integer because is also a common factor of . Note as well that since each is an integer, this means that is a common multiple of the 's that is smaller than the lowest common multiple ? This does not make sense, right? This is where we reach a (logical) contradiction for which the only way to resolve this is to conclude that the GCD cannot be greater than 1 all along, thus the 's from the start must be coprime!
We have thus demonstrated the technique of proof by contradiction to confirm the validity of this fact.