For example, How many 4 digit numbers are there which contains not more than 2 different digits?

Answer is 576 The first (non-zero) digit of the number F (thousands digit) can be any one of nine. The second digit S which is used if there are two digits can be any one of the nine digits different from the first.

Now consider the Hundreds Tens and Units digits in the case that there are two digits used in the number. We have two possibilities F or S to fill each place - but we exclude FFF as not involving two digits, so there are 23−1=7 possible patterns with exactly two different digits and 9×9 ways of choosing the pair of digits in the first place.

Then there are nine possibilities with just one digit.

So the total you want is 9×9×7+9=576


2 Answers 2


Going for the question in the title (5 digit number, exactly two different digits):

Pick two digits first: either two non-$0$ ones $a$ and $b$, in $\binom{9}{2}$ ways and then take all length 5 strings of them except $aaaaa$ and $bbbbb$ gives $\binom{9}{2}\cdot (2^5-2)$ ways.

We can also have $9$ pairs that contain a $0$ and one other digit, and then we don't count the ones starting with $0$, so the number must be of the form $a....$ where only $aaaaa$ is forbidden, so that's an extra $9 \cdot (16-1)$ options.

So in all $36 \cdot 30 + 9\cdot 15 = 1215$ options. I don't know where you got the $576$ but it seems off to me.

  • $\begingroup$ The number $576$ represents Indrajeet Bhattacharya's answer to the question "How many four-digit numbers are there which contain not more than two different digits?" Using your approach, we get $$\binom{9}{2}(2^4 - 2) + 9(2^3 - 1) = 36 \cdot 14 + 9 \cdot 7 = 504 + 63 = 567$$ four-digit numbers that use exactly two different digits and $9$ that use exactly one digit for a total of $576$. $\endgroup$ Jun 24, 2019 at 1:52
  • $\begingroup$ @N.F.Taussig nice observation. Thx. Why for 4 digits he chose for at most and not 2 different digits beats me, though. $\endgroup$ Jun 24, 2019 at 3:56

Well, the first digit can be any of 1---9, and the second could be any of 0---9 other than the first digit.

$$a \in \{ 1,2,\cdots,9\}, \quad b \in \{0,1,\cdots,9\} - \{a\}.$$

Each of the other five digits is either $a$ or $b$.

Number of five digit numbers with exactly two distinct digits is

$$n= 9\cdot 9 \cdot 2^3 =648.$$


The first two, three, or four digits could be the same non-zero digit:

Thus we must add these possibilities: $$aab**,$$ $$aaab*$$ $$aaaab,$$ which can occur in $$ 9\cdot 9 \cdot (2^2 +2 + 1) \textrm{ ways}.$$

The total is $$9\cdot 9 \cdot 15 = 1215.$$

  • $\begingroup$ The question is about 4-digit numbers, I believe. $\endgroup$ Jun 23, 2019 at 21:19
  • $\begingroup$ The title of the question is "The number of five digit $\cdots$" $\endgroup$
    – mjw
    Jun 23, 2019 at 21:21
  • $\begingroup$ As an example, the questioner asked and answered about four digit numbers. At least that's how I read the question. $\endgroup$
    – mjw
    Jun 23, 2019 at 21:22
  • $\begingroup$ But the first sentence says otherwise. It;'s confusing I, agree. $\endgroup$ Jun 23, 2019 at 21:22
  • $\begingroup$ @Indrajeet, what's your question, again? Thanks $\endgroup$
    – mjw
    Jun 23, 2019 at 21:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .