## Task A-4.4.

A natural number is said to be quirky if in its decimal representation it has 100 digits and if by removing any of its digits, a 99-digit number divisible by 7 is formed. How many quirky natural numbers are there?
## Solution.

Let $x=\overline{a_{99} a_{98} \ldots a_{1} a_{0}}$, and let $x_{k}$ be the number obtained by removing the digit $a_{k}$ from the number $x$.

If the numbers $x_{k}$ and $x_{k+1}$ are divisible by 7 and their difference $x_{k+1}-x_{k}$ is also divisible by 7.

Since the numbers $x_{k}$ and $x_{k+1}$ differ by only one digit, their difference is

$$
x_{k}-x_{k+1}=10^{k}\left(a_{k+1}-a_{k}\right)
$$

However, the numbers 7 and 10 are relatively prime, so we conclude that 7 divides $a_{k+1}-a_{k}$, i.e., $a_{k+1}$ and $a_{k}$ give the same remainder when divided by 7 for all $k=0,1, \ldots, 98$.

We conclude that the number $x$ is quirky only if all its digits give the same remainder when divided by 7.

Let $p$ be the number consisting of 99 ones, i.e.,

$$
p=\overline{11 \ldots 1}=\frac{10^{99}-1}{9}
$$

The numbers $10^{n}$ for $n=1,2, \ldots$ give remainders $3,2,6,4,5,1,3,2, \ldots$ when divided by 7, which repeat periodically with a period of 6. Therefore, the number $10^{99}$ gives the same remainder when divided by 7 as $10^{3}$, i.e., a remainder of 6. Thus, $10^{99}-1$ gives a remainder of 5, so $p$ is not divisible by 7.

This also implies that for $k=2,3,4,5,6$ the number $k \cdot p$ is not divisible by 7.

For $k=1,2$, let $S_{k}$ be the set of all 99-digit numbers whose digits all give a remainder of $k$ when divided by 7.

The difference between any two elements $x, y \in S_{k}$ is divisible by 7. Since $p$ and $2p$ are not divisible by 7, no element of the set $S_{1}$ or $S_{2}$ is divisible by 7.

We conclude that the number $x=\overline{a_{99} a_{98} \ldots a_{1} a_{0}}$ is quirky only if all its digits give a remainder of 0 when divided by 7, i.e., only if $a_{i} \in\{0,7\}$ for all indices $i$.

The digit $a_{99}$ cannot be zero, otherwise $x$ would not be a 100-digit number, and $a_{98}$ cannot be zero either, otherwise $x_{99}$ would not be a 99-digit number.

Since for all the remaining digits $a_{0}, \ldots, a_{97}$ we have two possibilities (0 or 7), the total number of quirky numbers is $2^{98}$.