You are given a number $N\le 10^{18}$. You need to find out how many numbers there exist in between $1$ to $N$, which doesn't contain the digit $'X'$ in it . Say $N = 5, X=4$
The answer is $4$.
$1, 2, 3, 5$ are the numbers that doesn't contain $4$ in it . How can I solve this problem ?
I repeat between $1$ to $N$. $0$ is not countable. And $X$ will never be $0$.
Original version (mistaken):
Subtract $1$ from every digit in $N$ that is $≥X$. Then interpret $X$ as a base-$9$ number.
Edited to add:
This doesn't work if $N$ contains any digits equal to $X$. For example, if $X=3$, then for $N=20$ or $N=40$ we get $20_9 = 18$ and $30_9 = 27$ numbers respectively; but for $N=30$ we get $26$ numbers, not $20_9=18$ as my procedure predicts.
To get round this, we need a pre-processing stage. So now it looks like this: