The Remainder Walk
Start at C. Add the remainder N mod C. Repeat. The walk
can never step past N, so it must stop — and the only places it can stop are N
itself or a factor of N.
The Walk
Each hop adds the remainder. The coloured blocks under the line are the D's — laid end to end they fill the line from 0 to where the walk stops.
The River Map
Every start from 1 to N−1 at once. Each arc is one hop; follow the arcs rightwards and every start drains into N or into a factor, like streams into a river. Hover the line to trace a start.
The Leaky Sieve
Run the walk from 2 on every number. It behaves like a sieve that tries small factors — but the sieve has holes. Click any square to walk it.
Patterns in the Holes
Things the walk from 2 does that you can check for yourself.
Squares of primes slip through
For a prime p of 7 or more, the walk on p² almost always runs
straight past p. Its only doorway is p − 1, and the walk
hardly ever lands there. Among the 4 billion primes below 100 billion,
only five squares get caught: the three below, plus 499,198,207² and
3,807,362,441² (too big for this page to walk exactly).
5 has exactly one hole
For numbers not divisible by 2 or 3, the walk from 2 catches the factor 5 every time
except when N mod 60 = 55. Then it goes 2 → 3 → 4
→ 7 and jumps over 5. That is why 55, 115, 235, 295 and 355 all leak. (Checked for
every N below a million.)
The doorway rule
The walk can only step onto a prime factor p from a number between
p/2 and p that divides N/p − 1. On the
River Map those doorways are marked with rings. 1081 has none for 23 or 47, so nothing
but 23 and 47 themselves ever reaches them.
About 4 chances in p
Take numbers whose smallest factor is p. How often does the walk from 2 catch
it? Roughly 4/p of the time: 3 in 4 for p = 5, half for p = 7, about 1 in
25 for p = 101. Each bar below is 3,000 random numbers, run live in your browser; the
line is 4/p.