Our goal is to find the number of 3’s present in the prime factorization of 30!
To systematically count, we note the following:
Numbers like 1,2,4,5, and the like contribute zero factors of 3
Numbers like 3,6,12,15 and the like contribute one factor of 3
Numbers like 9 and 18 contribute two factors of 3
27 contributes three factors of 3
As such, our first pass would involve counting numbers contributing at least one factor of 3. We know that there are 10 such terms because every multiple of 3 in [1,30] works.
For our second pass, we count numbers contributing at least a second factor of 3. We know that if a number has two factors of 3 then it must be a multiple of 9. Owing to that, we count the multiples of 9 in [1,30], which happens to be 3 in quantity.
For our final pass, we count numbers contributing at least a third factor of 3. Needless to say, if a number has at least 3 factors of 3 then it must be a multiple of 27. There happens to be exactly one multiple of 27 in [1,30].
Putting all the counts together leads us to 10 + 3 + 1.
It’s mostly a logical flaw from your side in applying the formula. Building from the logic I outlined above should allow you to incorporate your “multiples formula”.