Interesting use of remainder theorem I am asking this question in reference to this post Write an Efficient Method to Check if a Number is Multiple of 3
In the proof of the method the author writes that any 2 digit number(AB) can be written in the form $$AB=11A-A+B$$Any 3 digit number(ABC) can be written as $$ABC = 99A + A + 11B – B + C = (99A + 11B) + (A + C – B)$$ And a 4 digit number(ABCD) as $$ 1001A + D + 11C – C + 999B + B – A$$
I have tried a few test cases and it works. But how did he come up with such an observation. And how can I represent a 5 digit number in this way?
Thanks in advance 
 A: Considering congruences modulo $11$ is easier:
\begin{align}
10^0 & \equiv 1 \pmod{11} \\
10^1 & \equiv 10 \equiv -1\\
10^2 & \equiv -1\cdot 10\equiv -1\cdot(-1)\equiv 1\\
10^3 & \equiv 1\cdot 10\equiv 1\cdot(-1)\equiv -1\\
&\dots\\
10^{2k} & \equiv -1\cdot 10\equiv -1\cdot(-1)\equiv 1\\
10^{2k+1} & \equiv 1\cdot 10\equiv 1\cdot(-1)\equiv -1
\end{align}
Thus every power of $10$ is either congruent to $1$ (for even exponents) or to $-1$ (for odd exponents). This means that when you write a number as
$$
a_0+a_1\cdot 10^1+a_2\cdot 10^2+\dots+a_n\cdot 10^n
$$
you can substitute $10^{2k}$ with $1$ and $10^{2k+1}$ with $-1$ and this will make the new number differ from the old one by a multiple of $11$. In particular, checking whether the old number is divisible by $11$ is the same as checking the new number. In the case of five digits, the number is
$$
a_0+a_1\cdot 10+a_2\cdot 10^2+a_3\cdot 10^3+a_4\cdot 10^4
$$
and the number you can consider is
$$
a_0-a_1+a_2-a_3+a_4
$$
For two digits, $a_0+a_1\cdot 10$ becomes $a_0-a_1$, and so on.
A: It's hard to say how he came up with that observation, but by experimentation you can perhaps see a pattern in which numbers are divisible by $11$ and proceed from there to figure out why it works. Here's one proof that leads to the decomposition he gives.
Note that if $n=2k+1$ is odd, then
$$10^n+1 = 10^{2k+1}+1 = (10+1)(10^{2k} - 10^{2k-1} + \cdots) = 11r,$$
while if $n=2k$ is even, then
$$10^n-1 = 10^{2k}-1 = (10^2-1)(10^{2k-2} + 10^{2k-4} + \cdots) = 11\cdot 9s.$$
So if you have the decimal representation of some number, you can write it as a multiple of $11$ plus some remainder using the above, by writing the digit $d$ corresponding to $10^n$ as either a multiple of $11$ times $d$ minus $d$ or a multiple of $11$ times $d$ plus $d$, depending on whether $n$ is even or odd. Then adding up the remainders gives you the formula you want. And the numbers in your test cases come from the numbers $10^2-1 = 99$, $10^3+1 = 1001$ (note that your decomposition for a 4-digit number has an extra $9$). So you get
\begin{align*}
  10A+B &= (11A-A)+B \equiv -A+B\mod{11} \\
  100A+10B+C &= (99A+A)+ (11B-B)+C\equiv A-B+C\mod{11} \\
  1000A+100B+10C+D &= (1001A-A)+(99B+B) + (11C-C)+D \\
     &\qquad\equiv -A+B-C+D\mod{11} \\
  10000A + 1000B + 100C + 10D + E
    &= (9999A+A) + (1001B-B) + (99C+C) + (11D-D) + E \\
    &\qquad\equiv A-B+C-D+E\mod{11}.
\end{align*}
