Count how many multiples of 8, 12, or 18 there are in the range {1, 2, 3, …, 300}:
⌊300/8⌋ = 37
⌊300/12⌋ = 25
⌊300/18⌋ = 16
(where ⌊n⌋ denotes the floor of n, i.e. the largest integer that is smaller than n; for instance, 300/8 = 37.5, so ⌊300/8⌋ = ⌊37.5⌋ = 37)
Take pairwise LCMs, as well as the LCM of all three numbers:
LCM(8, 12) = LCM(2³, 2²×3) = 2³×3 = 24
LCM(8, 18) = LCM(2³, 2×3²) = 2³×3² = 72
LCM(12, 18) = LCM(2²×3, 2×3²) = 2²×3² = 36
LCM(8, 12, 18) = LCM(2³, 2²×3, 2×3²) = 2³×3² = 72
Count how many multiples there are of each of these LCMs that are less than 300:
⌊300/24⌋ = 12
⌊300/72⌋ = 4
⌊300/36⌋ = 8
Then, using the inclusion/exclusion principle, the number of numbers less than 300 that are exactly divisible by 8, 12, or 18 is
{multiples of 8} + {multiples of 12} + {multiples of 18}
- {multiples of 24} - {multiples of 72} - {multiples of 36}
+ {multiples of 72}
= 37 + 25 + 16 - 12 - 4 - 8 + 4 = 58