How many multiples of 7 contain a 7 in their decimal representation?

85 Views Asked by At

The first few multiples of $7$ that contain a $7$ in their decimal representation are $7, 70, 77, 147, 175, 217 ..$ (OEIS A121027).

My question is how many such numbers exist below $n$:

$$ f(n) = \left| \left\{ x \lt n : x \equiv 0 \bmod 7 \land \text{$x$ contains a '7'} \right\} \right| $$

It seems that $f(7 \cdot 10^c) = 10^c - 9^c$, e.g. there are exactly $10^3 - 9^3 = 271$ multiples of $7$ that contain a $7$ below $7000$. A proof for this has been given on MathOverflow.

Using the above fact, it is also easy to find $f(n)$ for any $n$ starting with a $'7'$.

$$\forall m<10^c, f(7 \cdot 10^c + m) = 10^c - 9^c + \lceil m/7 \rceil $$

I'd like to know how many such numbers exist below $n$ in general, in the form of a (possibly recursive) function.

1

There are 1 best solutions below

2
On

Copying my answer from MO:


The proof of $f(7 \cdot 10^n) = 10^n - 9^n$ is easy. There are $9^n$ numbers below $10^n$ that do not contain a '7', including zero. Let $M$ be such a number. Since $10^n \not\equiv 0 \bmod 7$, there is a unique $a$ with $0 \leq a \leq 6$ such that $N = a \cdot 10^n + M$ is divisible by $7$. It is clear that $N$ does not contain a 7. It is also clear that this accounts for all $x$ with $0 \leq x < 7 \cdot 10^n$ which are divisible by 7 and do not contain a 7 in their decimal representation (since, given $N$, I can just cut off its first decimal to obtain the corresponding $M$). So, restricting to positive numbers, the total number of such $x$ thus comes to $9^n-1$. Hence the number of $x < 7 \cdot 10^n$ which are divisible by 7 and do contain a 7 is equal to $(10^n-1)-(9^n-1) = 10^n-9^n$.