Blog · Recreational maths

Recreational mathematics

Puzzles, paper folding and mathematical games: things that need no prerequisites but still hide real mathematics.

§

Articles

§

Proofs without words

§

Interactive labs

Small applets to play with, each with a short note on the mathematics behind it.

Probabilistic number theory

Erdős–Kac Lab

The number of prime factors of a random integer is normally distributed, but only just. Compare exact counts with the Gaussian and with an independent-primes model, over $\mathbb{Z}$ and over $\mathbb{F}_q[t]$.

appletnumber theory
Projective geometry

Shadow Projection

A point light casts the shadow of a quadrilateral onto the floor. Move the lamp, tilt the card, and read off the $3 \times 3$ projective matrix and its vanishing line.

appletgeometry
Elementary number theory

Zagier's Windmills

Why every prime $p \equiv 1 \pmod 4$ is a sum of two squares, by redrawing windmill pictures. Apply Zagier's one-sentence involution and walk from the plus sign to $p = x^2 + (2y)^2$.

appletnumber theory
Metric number theory

The digits of a random number

Expand a number as a continued fraction and watch its digits follow the Gauss–Kuzmin law, with the geometric mean closing in on Khinchin's constant $2.6854\ldots$. Then try $e$, $\sqrt2$ and $\sqrt[3]{2}$.

appletnumber theory
Combinatorics

Pascal's triangle, coloured by p

Each $\binom{n}{k}$ coloured by the power of $p$ dividing it: a fractal explained by Kummer's theorem, the number of carries when adding $k$ and $n-k$ in base $p$.

appletcombinatorics
Diophantine approximation

The three-gap theorem

Step around a circle by an irrational fraction of a turn: however many points you place, the gaps come in at most three lengths, and the longest is the sum of the other two.

appletcontinued fractions
Mathematical physics

Hofstadter's butterfly

Energies of an electron on a grid in a magnetic field, one row per fraction $p/q$: $q$ bands each, a fractal butterfly, and a Cantor set for irrational flux (the Ten Martini problem).

appletFarey fractions
Rational numbers

Every fraction exactly once

A binary tree that lists every positive fraction once, in lowest terms; Stern's sequence that reads it off; and Minkowski's ?(x), which turns continued fractions into binary.

appletrational numbers
Algorithms

Pollard's rho

Iterate $x \mapsto x^2 + c$ modulo $n$: modulo a hidden prime factor the sequence falls into a loop shaped like ρ, and Floyd's tortoise and hare catch it in about $\sqrt p$ steps.

appletfactoring
Lattice points

Gauss's circle problem

Count lattice points inside a circle of radius $R$: about $\pi R^2$, with an error conjectured to be $R^{1/2+\varepsilon}$, proved only to about $R^{0.63}$.

appletlattice points
p-adic numbers

The p-adic integers as a fractal

Integers drawn by their base-$p$ digits as nested discs: watch $p^k - 1 \to -1$, $1 + p + p^2 + \cdots \to \frac{1}{1-p}$, Teichmüller roots of unity and Hensel's lemma at work.

appletp-adic
A good mathematical joke is better, and better mathematics, than a dozen mediocre papers.
J. E. LittlewoodA Mathematician’s Miscellany, 1953
§

Puzzle shelf

Short problems to think about over tea, from the International Mathematical Olympiad, the Putnam competition and the folklore. Click to reveal a solution.

How many of the numbers 1, 2, …, 100 are squarefree?
61. A number fails to be squarefree when it is divisible by $4$, $9$, $25$ or $49$. Inclusion–exclusion gives $100 - (25 + 11 + 4 + 2) + (2 + 1) = 61$, where the correction terms count the multiples of $36$ and of $100$. As $N \to \infty$ the proportion of squarefree numbers tends to $6/\pi^2 \approx 0.608$.
Fold the corner of a square to a point on the top edge. Where should it go so that the crease pattern marks the right edge at 3/5?
At $t = 1/4$. Haga's fold sends $t \mapsto \frac{1-t}{1+t}$, which is its own inverse, so solve $\frac{1-t}{1+t} = \frac35$. See the post on Haga's theorem.
Show that the fraction $\dfrac{21n + 4}{14n + 3}$ is in lowest terms for every natural number $n$. IMO 1959
Any common divisor of $21n + 4$ and $14n + 3$ divides $3(14n + 3) - 2(21n + 4) = 1$. A one-line Bézout argument, and a good warm-up for the rest of the shelf.
For which $n$ is $2^n - 1$ divisible by $7$? Show that $2^n + 1$ never is. IMO 1964
Since $2^3 = 8 \equiv 1 \pmod 7$, the powers $2^n \bmod 7$ cycle through $1, 2, 4$. So $7 \mid 2^n - 1$ exactly when $3 \mid n$, and $2^n + 1 \bmod 7$ cycles through $2, 3, 5$, never $0$.
Write $1 - \frac12 + \frac13 - \frac14 + \cdots - \frac{1}{1318} + \frac{1}{1319} = \frac pq$ in lowest terms. Prove that $1979$ divides $p$. IMO 1979
The alternating sum equals $\sum_{k=1}^{1319}\frac1k - 2\sum_{k=1}^{659}\frac{1}{2k} = \sum_{k=660}^{1319}\frac1k$. These $660$ terms pair up as $k$ and $1979 - k$, and $\frac1k + \frac{1}{1979 - k} = \frac{1979}{k(1979 - k)}$. So $\frac pq = 1979 \cdot \frac rs$ where $s$ is a product of numbers smaller than $1979$. Since $1979$ is prime it does not divide $s$, and from $ps = 1979\,rq$ we get $1979 \mid p$.
Positive integers $a, b$ are such that $ab + 1$ divides $a^2 + b^2$. Show that $\dfrac{a^2 + b^2}{ab + 1}$ is a perfect square. IMO 1988
Let $k$ be the quotient and suppose it is not a square. Among all pairs with $a^2 + b^2 = k(ab + 1)$, take one with $a \ge b$ and $a + b$ minimal. As a quadratic in $a$, $a^2 - kb\,a + b^2 - k = 0$ has a second root $a' = kb - a = \frac{b^2 - k}{a}$, an integer. If $a' < 0$ then $a'^2 - kba' + b^2 - k > 0$, impossible; if $a' = 0$ then $k = b^2$ is a square. So $a' > 0$ and $a' = \frac{b^2 - k}{a} < \frac{b^2}{a} \le a$, giving a smaller pair $(a', b)$. Contradiction. This is Vieta jumping, the same move as in the Markov tree; the problem is famous because none of the six members of the Australian committee that vetted it could solve it.
Prove that for every $n$ there are $n$ consecutive positive integers, none of which is a power of a prime. IMO 1989
Choose $2n$ distinct primes $p_1, q_1, \dots, p_n, q_n$. By the Chinese remainder theorem there is $x$ with $x \equiv -i \pmod{p_i q_i}$ for $i = 1, \dots, n$. Then $x + i$ is divisible by two different primes $p_i$ and $q_i$, so it is not a prime power.
Let $a_n = 2^n + 3^n + 6^n - 1$. Find all positive integers that are coprime to every term of the sequence. IMO 2005
Only $1$. The term $a_2 = 48$ is divisible by $2$ and $3$. For a prime $p \ge 5$, Fermat's little theorem gives $6a_{p-2} = 3 \cdot 2^{p-1} + 2 \cdot 3^{p-1} + 6^{p-1} - 6 \equiv 3 + 2 + 1 - 6 = 0 \pmod p$, so $p \mid a_{p-2}$. Every prime divides some term, so any number larger than $1$ shares a factor with some term.
Prove that $\dfrac{\gcd(m, n)}{n}\dbinom{n}{m}$ is an integer for all integers $n \ge m \ge 1$. Putnam 2000
Write $\gcd(m, n) = am + bn$ with integers $a, b$. Then $\frac{\gcd(m,n)}{n}\binom nm = a \cdot \frac mn\binom nm + b\binom nm = a\binom{n-1}{m-1} + b\binom nm$, an integer. With $n = 2k + 1$ and $m = k$, which are coprime, it shows that $\frac{1}{2k+1}\binom{2k+1}{k}$ is an integer; this is the Catalan number $\frac{1}{k+1}\binom{2k}{k}$.
Let $T_1 = 2$ and $T_{k+1} = 2^{T_k}$, so $T_k$ is a tower of $k$ twos. Prove that $T_n \equiv T_{n-1} \pmod n$ for every $n \ge 2$. Putnam 1997
We prove the stronger claim that $T_k \equiv T_{k-1} \pmod N$ whenever $k \ge N \ge 1$, by induction on $N$ ($N = 1$ is trivial; small $k$ are checked directly). Write $N = 2^a m$ with $m$ odd. Modulo $2^a$: both $T_k = 2^{T_{k-1}}$ and $T_{k-1} = 2^{T_{k-2}}$ are powers of $2$ with exponents at least $k - 1 \ge N - 1 \ge a$, so both are $\equiv 0$. Modulo $m$: since $\gcd(2, m) = 1$, Euler's theorem says $2^x \equiv 2^y \pmod m$ whenever $x \equiv y \pmod{\varphi(m)}$, and $T_{k-1} \equiv T_{k-2} \pmod{\varphi(m)}$ by the induction hypothesis, because $\varphi(m) < N \le k - 1$. The Chinese remainder theorem combines the two.
Show that $1 + \frac12 + \frac13 + \cdots + \frac1n$ is never an integer for $n \ge 2$. classic, Taeisinger 1915
Let $2^s$ be the largest power of $2$ that is at most $n$, and $L = \mathrm{lcm}(1, \dots, n) = 2^s m$ with $m$ odd. In $L \cdot H_n = \sum_{k \le n} L/k$, every term is even except the one with $k = 2^s$, because no other $k \le n$ is divisible by $2^s$; that term is $m$, odd. So $L \cdot H_n$ is odd. If $H_n$ were an integer, $L \cdot H_n$ would be even, since $L$ is.
Prove that among any $n$ integers, some nonempty group of them has a sum divisible by $n$. classic pigeonhole
Look at the partial sums $S_1 = a_1$, $S_2 = a_1 + a_2$, …, $S_n$ modulo $n$. If one is $0$ we are done. Otherwise $n$ sums take at most $n - 1$ nonzero values, so $S_i \equiv S_j$ for some $i < j$, and $a_{i+1} + \cdots + a_j$ is divisible by $n$. The group can even be chosen consecutive. (The much harder Erdős–Ginzburg–Ziv theorem says that among any $2n - 1$ integers, some $n$ of them have a sum divisible by $n$.)
$n$ people stand in a circle. Going round, every second person leaves: person $2$, then $4$, and so on, wrapping around. Who is left last? the Josephus problem
Write $n = 2^m + L$ with $0 \le L < 2^m$. The survivor is $J(n) = 2L + 1$. After one lap with $n = 2k$ people, the $k$ odd-numbered people remain, giving $J(2k) = 2J(k) - 1$; with $n = 2k + 1$, person $1$ also leaves right after person $2k$, giving $J(2k+1) = 2J(k) + 1$. These recursions with $J(1) = 1$ give the formula. In binary: move the leading $1$ of $n$ to the end, so $J(41) = J(101001_2) = 010011_2 = 19$.
Chomp: a rectangular chocolate bar, not $1 \times 1$, has a poisoned top-left square. Players alternately pick a square and eat it together with every square below and to the right of it. Whoever eats the poison loses. Show that the first player can always win. Gale 1974
Strategy stealing. Suppose the second player had a winning strategy. Let the first player eat only the bottom-right square, and let the second player answer with a winning move. But that answer removes a block containing the bottom-right square, so the first player could have made that very move at the start and then followed the second player's strategy. A finite game without draws has a winner, so the first player wins. The argument proves this without saying what the winning move is, which for general rectangles nobody knows.
$100$ prisoners stand in a line, each wearing a black or white hat. Each sees the hats in front of them, not their own or those behind. From the back, each calls out a colour; those who name their own hat go free. Agreeing on a plan beforehand, how many can be guaranteed to go free? folklore
$99$. The last prisoner says "black" if they see an odd number of black hats and "white" otherwise; they are free with probability $\tfrac12$. Every later prisoner knows that parity, sees the hats in front, and has heard the colours called by those behind (all correct), so they can work out their own colour. This is a parity check, the simplest error-correcting code.