In general, the principle is to count everything without worrying if anything is double counted. Then subtract any double counting that may occur. If you throw away anything more than once (double counting the throw-away's) then add these back and so on. All this double counting etc. is best expressed in the language of intersection of sets.
In response to OP's request
Here is a simple example: How many numbers (exluding zero) less than 33are divisible by $2$, $3$ or $5$?
There are 16 numbers divisible by 2: 2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32
There are 10 numbers divisible by 3: 3,6,9,12,15,18,21,24,27,30
There are 6 numbers divisible by 5: 5, 10, 15,20,25,30
There are 5 numbers divisible by 2 and 3: 6, 12, 18,24,30
There is 3 number divisible by 2 and 5: 10, 20, 30
There is 2 number divisible by 3 and 5: 15, 30
There is 1 number divisible by all 3: 30
So if you add all the numbers divisible by 2 ,3 or 5 without worrying about double counting
you get
$$16+10+6 = 32$$
Numbers divisible by two or more get counted twice, so we have to subtract
$5 + 3 + 2 = 10$
Now the number 30 gets thrown out so add it back
So the final answer is
$32 - 10 + 1 = 23$
Here they are:
$$1,3,5,6,7,9,10,11,12,13,15,17,18,19,20,21,23,24,25,27,29,30,
31$$