Let's say you sit in a pub, minding your own business, when all of a sudden a stranger walks up to you and offers you a bet:

We'll choose two positive integers at random. If they have any divisor in common (other than ) I'll pay you a dollar, else you'll pay me a dollar. Are you in?

Apart from the question what kind of establishments you frequent, you should be wondering: is this a good bet for you?

When two integers have no divisors in common except the trivial divisor we say they are *coprime* or *relatively prime*. and have the common divisor , so they are *not* coprime, whilst and only have the trivial common divisor , so they are coprime.

This makes you start thinking: "As numbers grow bigger, aren't there a lot of divisors out there? After all, half the numbers are even, so if we hit two even numbers, they'll have the factor in common and I'll win. And then there's , , , ... Seems like a good deal!"

Is it, though? Let's do some experiments! This simply Python script should give a decent approximation:

from math import gcd from random import randint from sys import maxsize repetitions = 10**8 count = sum(1 if gcd(randint(1, maxsize), randint(1, maxsize)) == 1 else 0 for _ in range(repetitions)) print('{count:d} out of {repetitions:d} pairs were coprime ({pct:.3f}%)' .format(count=count, repetitions=repetitions, pct=100 * count / repetitions))

This will pick two (largish) integers at random^{1}, check if they are coprime – which is the same as saying that they're greatest common divisor (*gcd*) is – and repeat the procedure 100 million times. At the end, it will print something like this:

60797595 out of 100000000 pairs were coprime (60.798%)

If you run this, the exact numbers will obviously be different, but the bottom line is that in over 60% of the cases you'll end up with two coprime numbers. Don't take the bet! (This is generally a good rule of thumb when a stranger makes you any kind of offer.)

So, where does that number – ish – come from? There is a nice and easy representation of the exact number, and if you've never heard of this problem, you might be surprised that the answer involves – the ubiquitous constant of circle fame. What's it got to do in number theory? Quite frankly, I'm not sure, but we can prove it, so bear with me.

First, let's look at the above probability more closely. For two numbers to have a non-trivial common divisor means in particular that there is a prime that divides both of these numbers. If they are coprime, then there's no prime dividing both of them. What are the odds of that? Well, half the numbers will be divisible by – the even numbers. The probability that both numbers are even is , so the probability that they are not divisible by is the complement . Likewise, a third of all numbers are divisible by , so the probability of having as a common factor is , with a complement of .

We can consider the probabilities of being divisible by any two given prime numbers as independent, so we can just multiply all these terms together for the probability that two integers are coprime:

where the product runs over all primes . This should look awfully familiar to you. If it's been to long and I need to jog your brain, remember the Euler product that is at the very core of our investigations:

In other words, our probability is nothing but

The value of this particular sum became rather famous in its own right as the **Basel problem**, first posed in 1644 and finally solved in 1734 by none less than the great Leonhard Euler. By now, dozens of proofs have been published, most of which calculate some form of integral, but none is clearer and more beautiful than the master's original one, so let's dive into that.

We'll obtain two series representations of and compare them with one another. First, let's take a look at the **Taylor series** of the sine function. In general, this series is defined for a smooth (read: well-behaved) function as

where is the factorial function and is the -th derivative of evaluated at . The derivates of are about as easy as they get:

from where it all begins over and over in a neat -cycle. In particular we have , , and , which yields the following classic series representation for the sine-function:

We'll take one out of the sum and use the slightly different form

Half way there. Now we'll develop a product representation for , more precisely an expression over its zeros. We used a very similar expression when we developed the product representation for . The general form is

where the product runs over all the zeros of . Euler was very much ahead of his time in using such a product and just manipulated formal expressions, much like in the famous sum . It wasn't until the late 19th century, when Karl Weierstraß formally proved products like this in an attempt to verify some of the claims in Riemann's famous paper.

Now, remembering that has zeros for all with , and as , we can write

This is a product of sums in , so if we manage to multiply out everything we'll have another series representation of . In general, multiplying out such an expression means for every choosing either the left () or the right () summand and then summing everything up over all possible combinations (like *left, left, left, ...* or *left, right, left, ...*). This is actually much easier than it sounds since we don't need to deal with all the infinite coefficients which in turn will be infinite sums. Instead, all we care about are the terms that contain . Because all factors of the product above are of the form this means we choose for one the right summand and the left ones (which are all ) for everything else. Hence the above product will expand into a series like so:

The rest will be higher order terms of degree or more which we don't care about. What we've obtained are two series representations for , both of the form . It's pretty easy to show that if you have two such series for the same function, all of their coefficients must be identical. This means in particular that the coefficients in front of must match. From the Taylor series we got , while the product yielded , so we just obtained the equality

We can take the s out of the series since they don't depend on and rearrange a little to finally arrive at Euler's solution to the Basel problem:

Using this in our calculations above we obtain the exact result for the probability that two randomly chosen positive integers are coprime:

As I said before, I'm still puzzled every time I work on this how the trigonometric constant manages to creep up all over maths in seemingly unrelated fields.

Euler's solution I presented here lacks some form of rigour since he couldn't prove that the product representation actually converges, but his manipulations as formal identities not only solved the famous Basel problem correctly, it can actually do lot more. When multiplying out the product above I ignored any terms higher than . However, if you do carry out these calculations you'll get expressions in , so you'll obtain similar results for all . The exact calculations are well beyond our scope here, but it's worth noticing that Euler solved the values of for all even integers, and in particular we know therefore that all are irrational and even transcendental numbers since they are expressions in . You might ask: what about odd arguments ?

Somewhat surprisingly the answer is: very little. It wasn't until 1978 that Roger Apéry proved that , a number that's now referred to as *Apéry's constant*, is irrational. No other value of is known to be irrational^{2} (or rational for that matter), let alone any nice closed form like we had with .

I'll leave you with the somewhat comforting note that Apéry was of the almost biblical age (for a mathematician) of over 60 years when he made his breakthrough. Mathematics is often called "a young men's discipline" – you either make a significant contribution before you reach tenure or you never will. Roger Apéry is one counter-example, Andrew Wiles and Yitang Zhang are others. It's never too late to start working on that one big theorem!

I was (deliberately) vague when saying

*choose two random numbers*. There is no way of choosing two*arbitrarily large*integers uniformly at random, so what you need to do is pick an upper bound*N*and choose numbers below*N*uniformly at random. In the calculations of the probabilities you'd take the limit*N*→ ∞. But we'll be hand-waving to begin with, so no reason to be exact here. ↩Some progress has been made, but no single value has been cracked so far. ↩