← All projects / Remainders Without a Zero

Remainders without a zero

Casting out nines finds a number's remainder by 9 by adding its digits. The test for 11 adds them with alternating signs. Both are one trick, and it works in any base, including the zero-free ones that use the digits 1 to b instead of 0 to b − 1: cut the digits into blocks, then add the blocks, or add them with alternating signs.

Try it

Pick a base and a divisor and type a number. It's written in that base without a zero, then the digits are folded until the remainder can be read off.

The rule

Find the block length

Keep multiplying by the base and look at the remainder by your divisor. The first time it comes out as 1, that's the block length, and the blocks are added. If it comes out as 1 less than the divisor first, which is the same as −1, the blocks are added with alternating signs.

Why it works

Each block is worth its own value times a power of bk. If bk leaves 1, every such power leaves 1, so each block counts at face value. If it leaves −1, the powers alternate between 1 and −1.

Why a missing zero doesn't matter

The trick only uses powers of the base. Zero-free digits are worth the same powers as ordinary ones, so folding them gives the same remainder. The blocks just read differently: zero-free base 3 writes 13 as 111, ordinary base 3 also writes it as 111, but 3 is 3 in one and 10 in the other.

When the divisor goes into the base

If every prime in the divisor also divides the base, the last few digits are enough: 13 into zero-free base 13 needs only the last digit, with the digit 13 read as 0. If the divisor shares some primes with the base but not all, there's no single digit trick. Split it into its parts instead.

Every base and divisor up to 16

Each cell says how to find the remainder: +k add blocks of k digits, ±k add blocks of k with alternating signs, end k read the last k digits, and · for no single digit trick. Touch a cell to try it above.

add blocksalternate blockslast digits

13 in three bases

In base 3: add blocks of 3

27 leaves 1 on dividing by 13, because 13 is 111 in base 3. That's the fold behind Which Primes Split, Read in Base 3.

In base 10: alternate blocks of 3

1,000 leaves −1 on dividing by 13, because 1,001 = 7 × 11 × 13. The same alternating sum of three-digit blocks tests for 7 and 11 at once.

In base 13: the last digit

13 goes into its own base, so the last digit is the remainder. Zero-free base 13 writes the digit 13 where ordinary base 13 writes 0.

Casting out nines and the tests for 11 and for 7, 11 and 13 together are centuries old. What's here is the same trick written once for every base, with or without a zero.