987654321 = 8 x 123456789 + 9
98765432 = 8 x 12345678 + 8
9876543 = 8 x 1234567 + 7
987654 = 8 x 123456 + 6
...
9 = 8 x 1 + 1

Saul Foresta explained as follows why this pattern holds in the decimal system and in other number systems using bases other than base 10:

I generalized the problem for any base n and any number of digits r where r can be anywhere from 1 to (n - 1).

Then after rewriting both sides of the equality given in the problem using sigma notation I arrived at the following:


k=1 r(n-k) nr-k =(n-2) k=1 r knr-k +r

In each summation k stands for the kth digit of the number we're dealing with, reading from left to right. For example, in the number 9876, k ranges from 1-4, where 9 is k=1, 8 is k=2, and so on.

So all I need to do in order to prove that this pattern holds is show that the left side of this equality does indeed equal the right side. Taking the terms like 8 x 123456789, that is


(n-2) k=1 r knr-k

over to the left hand side, we will prove that this expression is equal to r.

[(n-1)n r-1 + (n-2)n r-2 + (n-3)n r-3 + ... + (n-r)] - (n-2)[n r-1 + 2n r-2 + 3n r-3 + ... + r] =
[n r - n r-1 + n r-1 - 2n r-2 + n r-2 - 3n r-3 + ...+ n - r] - [n r - 2n r-1 + 2n r-1 - 2.2n r-2 + ... + (n-2)r]

The coefficient of n r-k on this left hand side is [1-k] - [k+1-2k] = 0 for

(1kr-1) and the coefficient of n r is also 0.

The coefficient of n 0 is [-r] - [-2(r)] = r and hence this expression is equal to r as required.