# How many integers satisfy the condition?

So the question is:

How many integers $n$ satisfy:

• $9999<n<99999$

• All of it's digits are in $\left\{ 1,2,3,4,5\right\}$

• The tens digit is either $1$ or $3$

• The number of times $1$ appear is equal the the ones digit.

I broke it down into 5 cases for the possible digits of one, and looked at each separately, dividing some again into cases for each digit for ten. Which got me a final answer of $138$. But I was wondering if there's a smarter way of doing this.

• One good practice is always to tackle the one with maximum contraints first. You seem to have done that. In this case a real shortcut may not be available – Shailesh Oct 21 '15 at 16:57

• The ones digit is 1. In this case, it must be the only 1 in the number. So we have 1 option for the tens and 4 options for the other three. This gives $1 \times 4^3 = 64$ numbers.
• The ones digit is not 1. Then it is uniquely determined by the number of ones in the number and we must have at least 2 occurrences amongst the remaining 4 digits. We can use inclusion-exclusion to get: $2 \times 5^3 - 1 \times 4^3 - 1 \times 4^3 - 1 \times \binom{3}{1} \times 4^2$.
So the total result is: $2 \times 5^3 - 1 \times 4^3 - 1 \times \binom{3}{1} \times 4^2 = 138$ numbers satisfying your constraints.