First, an observation In base with b, there are b^{n â€“ 2}
ndigit numbers beginning with any particular digit (not equal to 0)
and divisible by b. For example in base 5, there would be 5^{4} 6digit numbers beginning with 1, 5^{4} 6digit numbers beginning with 2, 5^{4} 6digit numbers beginning with 3,â€¦ 5^{4} 6digit numbers beginning with 4 which are divisible by 5. Letâ€™s see the proof of this observation:
Observation 1: One out of every n consecutive numbers is divisible by n.
Observation 2: Consider a base b. If you need to
form ndigit numbers in base b, the first place can be filled in b  1
ways (you cannot use 0) and the remaining n  1 places can be filled in
b ways. Remember that in base b, you have b digits, 0 to b  1.
Therefore, the total ndigit numbers you can form = (b  1) Ã— b^{n }^{ }^{1 }. Since these would be consecutive numbers, the number of numbers divisible by b is = (b  1) Ã— b^{n }^{ }^{1 }/b = (b  1) Ã— b^{n }^{ }^{2 }. Out of these (b  1) Ã— b^{n }^{ }^{2 }numbers, b^{n }^{ }^{2 }will be beginning with 1, b^{n }^{ }^{2 }will be beginning with 2, â€¦, b^{n }^{ }^{2 }will be beginning with b  1.
When you write numbers using only 0, 1 and 2, you are writing in base 3.
Therefore, 3 digit numbers in base 3 beginning with 1 and divisible by 3 = 3
4 â€“ digit numbers in base 3 beginning with 1 and divisible by 3 = 9
5 â€“ digit numbers in base 3 beginning with 1 and divisible by 3 = 27
6 â€“ digit numbers in base 3 beginning with 1 and divisible by 3 = 81
7 â€“ digit numbers in base 3 beginning with 1 and divisible by 3 = 243
8 â€“ digit numbers in base 3 beginning with 1 and divisible by 3 = 729
9 â€“ digit numbers in base 3 beginning with 1 and divisible by 3 = 2187
There will not be a 9 digit number beginning with 2 and less than 200000000.
Therefore, 3 digit numbers in base 3 beginning with 1 and divisible by 3 = 3
4 â€“ digit numbers in base 3 beginning with 2 and divisible by 3 = 9
5 â€“ digit numbers in base 3 beginning with 2 and divisible by 3 = 27
6 â€“ digit numbers in base 3 beginning with 2 and divisible by 3 = 81
7 â€“ digit numbers in base 3 beginning with 2 and divisible by 3 = 243
8 â€“ digit numbers in base 3 beginning with 2 and divisible by 3 = 729.
Therefore, total number of numbers = 2(3 + 9 + 27 + 81 + 243 + 729) + 2187 = 4373.
