← All projects / Reading a Number in Base 3

Reading a number in base 3

Write a number in zero-free base 3, with the digits 1, 2 and 3, and its remainders by 3, 4, 9 and 12 can be read straight off the digits. You only need two readings: the last digit, and all the digits added with alternating signs.

Take a number apart

Three readings

The last digit ÷ 3

Every digit to its left is worth a multiple of 3, so only the last digit is left over. A last digit of 3 means it divides exactly.

Alternate the signs ÷ 4

3 is one less than 4, so by 4 the place values go 1, −1, 1, −1. Add the digits from the right with alternating signs, then take the remainder of that.

The last two digits ÷ 9

The places from 9 up are multiples of 9, so the last two digits decide it. If it isn't a multiple of 3, it's a square by 9 exactly when it ends in 1, whatever the digit before.

Both at once: ÷ 12

12 is 3 times 4, so the remainder by 12 is pinned down by the two readings together. The last digit picks the row and the alternating sum picks the column. Each of the 12 remainders has exactly one cell.

the square (1)not squares (5, 7, 11)shares a factor with 12

Only 2 and 3 can land in a dashed cell, since every other prime shares no factor with 12. So every prime after 3 sits in one of the four coloured cells, and those four are the teams in the mod 12 race.

The first primes

Each card shows the prime in zero-free base 3 with its last digit marked, the alternating sum, and the cell it lands in. Touch one to take it apart above.

Every prime below a million

The same grid with every prime below 1,000,000 dropped into its cell, worked out in your browser. The four teams come out almost level. That near-tie, and which team keeps a nose ahead, is The Race.

Why the readings work

A number is its digits times the place values

In zero-free base 3 the place values are 1, 3, 9, 27, and so on, the same as ordinary base 3. The only difference is that the digits run 1 to 3 instead of 0 to 2, so 3 is written as one digit, 3, not as 10.

A remainder only cares about the place values

Replace each place value by its own remainder and the total has the same remainder as the number. By 3 every place but the last becomes 0. By 4 they become 1, −1, 1, −1. By 9 everything from the third place on becomes 0.

Two readings make one remainder

Because 3 and 4 share no factor, knowing a number's remainder by 3 and its remainder by 4 tells you its remainder by 12, and every pair of remainders happens exactly once. This is the Chinese remainder theorem, and the grid above is a picture of it.

Whether 3 is a square

The cell also tells you whether 3 is a perfect square by that prime. It is when the two readings agree, last digit 1 with sum 1 or last digit 2 with sum 3, that is remainder 1 or 11 by 12. That's the rule behind The Power-of-3 Primes.