How many times will the digit 5 come in counting from 1 to 99, excludi

How many times will the digit 5 come in counting from 1 to 99, excluding those numbers which are divisible by 3 ?

16
15
14
13
This question was previously asked in
UPSC CISF-AC-EXE – 2017
The digit 5 comes 16 times in counting from 1 to 99, excluding those numbers which are divisible by 3.
First, count the total occurrences of the digit 5 from 1 to 99. The digit 5 appears in the units place in 5, 15, 25, 35, 45, 55, 65, 75, 85, 95 (10 times). It appears in the tens place in 50, 51, 52, 53, 54, 55, 56, 57, 58, 59 (10 times). The number 55 contains the digit 5 twice. So, the digit 5 appears a total of 10 + 10 = 20 times.
Next, identify the numbers between 1 and 99 that contain the digit 5 and are divisible by 3. These numbers are:
– 15 (1+5=6, divisible by 3) – contains one 5
– 45 (4+5=9, divisible by 3) – contains one 5
– 51 (5+1=6, divisible by 3) – contains one 5
– 54 (5+4=9, divisible by 3) – contains one 5
– 57 (5+7=12, divisible by 3) – contains one 5
– 75 (7+5=12, divisible by 3) – contains one 5
These are 6 numbers. Let’s count the occurrences of the digit 5 *within* these numbers: 15 (one 5), 45 (one 5), 51 (one 5), 54 (one 5), 57 (one 5), 75 (one 5). Total occurrences of 5 in these numbers are 6.
The numbers containing 5 are: 5, 15, 25, 35, 45, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 65, 75, 85, 95.
The numbers from this list that are divisible by 3 are: 15, 45, 51, 54, 57, 75.
We need to count the 5s in the numbers *not* divisible by 3: 5, 25, 35, 50, 52, 53, 55, 56, 58, 59, 65, 85, 95.
Counting the 5s in this remaining list:
5 (one 5), 25 (one 5), 35 (one 5), 50 (one 5), 52 (one 5), 53 (one 5), 55 (two 5s), 56 (one 5), 58 (one 5), 59 (one 5), 65 (one 5), 85 (one 5), 95 (one 5).
Total count = 1 + 1 + 1 + 1 + 1 + 1 + 2 + 1 + 1 + 1 + 1 + 1 + 1 = 16.
The key is to correctly identify which numbers containing 5 are excluded (those divisible by 3) and then count the 5s in the remaining set of numbers that contain the digit 5.