Skip to main content

How often do coprime numbers appear?

· 7 min read

Coprime numbers, also known as relatively prime numbers, are integers that do not share any prime factors, or equivalently having a greatest common divisor (GCD) of 1. Although the definition of coprime integers are originally for a pair of integers, it can be extended to any number of integers due to its associativity.

When I first learnt about coprime integers in a number theory course, there was a question that was not covered during the course, nor did it occur to me until recently: what is the probability of choosing a pair of coprime integers at random1?

Hi Again, Pi

There turns out to be a definitive answer to this question with several well-established proofs, and it is quite an elegant one:

6π2=0.6079271...61%\frac{6}{\pi^2} = 0.6079271... \approx 61\%

Surprisingly, π\pi seems to appear out of nowhere in the answer, which makes this a topic that could make into 3Blue1Brown's "Why pi?" video series. However, this should look familiar to those who are familiar with the Basel problem, or the sum of reciprocals of perfect squares. In fact, they are very closely related.

A Straightforward Proof

There are several proofs of this result, including one by Dirichlet that has existed since all the way back to 1849, and one that involves a more advanced concept called lattice points (see Apostol's Introduction to Analytic Number Theory, Theorem 3.9), but there is actually a simpler, yet more insightful argument, presented by Simon Tiger, a budding prodigy mathematician.

He does not go for the usual brute-force, 'bottom-up' method of running through massive numbers of integer pair samples while checking for the coprimality of each pair and keeping track of the odds in order to see if the probability converges to a certain constant. Instead, he takes a 'top-down' approach by looking at the probability of a pair of integers having a greatest common divisor (GCD) of 22 or above.

What does this mean? Suppose that we call the first number x1x_1 and the second number x2x_2. Let's start with 22 as the target factor. For x1x_1 and x2x_2 to have an GCD of 22, they must at least both be divisible by 22. Since modular arithmetic tells us that we can group integers evenly based on their respective remainders after being divided by a certain factor, the probability of x1x_1 (resp. x2x_2) being divisible by 22 (i.e. having remainder zero) is 12\frac{1}{2}.

Note that 22 must be the highest common factor of x1x_1 and x2x_2, so if we divide both of them by 22, they cannot share any other factor (except for 11 of course). Note that this is exactly the definition of coprimality! In other words, we have obtained a pair of coprime integers (namely x12\frac{x_1}{2} and x22\frac{x_2}{2}) through this procedure. What is the probability of finding such a pair? That's exactly what we're looking for; let's call that value pp.

The key of the procedure just now is that it gives us an important characterisation of a pair of integers having a certain number as their GCD: they must both be divisible by said number, and after dividing them by that number, the new resulting pair must be coprime.

Why?

If x1x_1 and x2x_2 had other common factors greater than 11 (say, bb) after being divided by their GCD (denoted here as aa), then abab, which is greater than aa, should have been the GCD instead, leading to a contradiction.

What is the probability of finding an integer pair like this? The argument above tells us that it is the product of the probabilities, which represent the criteria that must be fulfilled simultaneously, that we obtained through the procedure, i.e. 1212p=p4\frac{1}{2} \cdot \frac{1}{2} \cdot p = \frac{p}{4}.

At this stage, you may have figured out that this procedure can be repeated for every other integer factors. For 33, we obtain 1313p=p9\frac{1}{3} \cdot \frac{1}{3} \cdot p = \frac{p}{9}; for 44, we obtain p16\frac{p}{16}, and so on. We can even deduce the general pattern: for a factor kk, the probability of an integer pair having kk as their GCD is pk2\frac{p}{k^2}. This general pattern even works for the case when k=1k = 1, because an integer pair having 11 as their GCD essentially means that they are coprime, so the corresponding probability is indeed pp.

Now, we see how everything comes together which helps us to obtain the value of pp that we want. Note that any integer pair has the GCD of any number. This means that the probability of obtaining any integer pair among the sea of all integer pairs, which is clearly 11, is equal to the sum of all probabilities of an integer pair having the GCD of any number, ranged over all integers! Rewriting this description into an algebraic equation, we obtain

k=1pk2=1.\sum_{\substack{k = 1}}^{\infty}\frac{p}{k^2}=1.

Rearranging the variables a bit yields

p=1kZ>01k2p=\cfrac{1}{\sum_{\substack{k \in \mathbb{Z}_{>0}}}\frac{1}{k^2}}     p=1π26=6π2.\implies p=\cfrac{1}{\frac{\pi^2}{6}}=\frac{6}{\pi^2}.

In other words, the probability pp of a randomly chosen integer pair being coprime is the reciprocal of the sum of reciprocal of squares! That's where the Basel problem, i.e. the reason why π\pi shows up in the solution, plays a role!

Extension to nn integers

Another cool part of this argument is that it can be easily extended to an arbitrary number of randomly chosen integers, say, nn of them.

By investigating nn possible integers, say, x1,x2,,xnx_1,x_2,\ldots,x_n instead of just two like before, calculating the probability of these integers having a certain number kk as their GCD now involves multiplying 1k\frac{1}{k} for nn times in total, followed by multiplying pp at the end as before.

In a similar vein, we then obtain that

p=1kZ>01kn.p=\frac{1}{\sum_{k \in \mathbb{Z}_{>0}}\frac{1}{k^n}}.

Does the denominator ring a bell? It is in fact the definition of the Riemann zeta function!

ζ(s)=n=11ns=11s+12s+13s+\zeta (s)=\sum _{n=1}^{\infty }{\frac {1}{n^{s}}}={\frac {1}{1^{s}}}+{\frac {1}{2^{s}}}+{\frac {1}{3^{s}}}+\cdots

Rather, for the special case of positive integers, it is more commonly known as the pp-series.

It may be tempting to ask what the probability will become as the number of integers chosen 'tends to infinity'. It may even be more tempting to deduce from the general formula we just obtained to conclude that the answer should be 11. However, this question is meaningless because there can be contradicting outcomes depending on what kind of infinite collections of integers we are considering. For instance, the probability is 00 for all even numbers, but is 11 for all positive integers; notice that both cases involve an infinite number of integers.

What if we consider a finite range of numbers and a finite number of choices instead? According to this paper, this probability seems to decrease as the number of choices increases, which is frankly an interesting result.

Other sources, further reading

Footnotes

  1. Technically, it is impossible to choose a positive integer truly randomly such that each choice occurs with the same probability. However, we can still make formal mathematical definitions about such 'randomness' to suit our needs here; see here or here for more information.