Arrangements and Combinations · Basic Rules
Lesson 4
There are \(\lfloor 1000/2 \rfloor =500\) numbers divisible by \(2\), and \(\lfloor 1000/3 \rfloor =333\) numbers divisible by \(3\). However, this does not imply that the answer to our problem is \(500+333\): some numbers are divisible by both \(2\) and \(3\). This means that we cannot use the sum rule: it requires the sets to be disjoint. Nonetheless, it is not difficult to generalize the sum rule: for any sets \(A\) and \(B\), it holds that \[|A \cup B|=|A| + |B| - |A \cap B| \ .\]

The answer to our problem is \(500+333-166=667\).
print(len([x for x in range(1000) if x % 2 == 0 or x % 3 == 0]))667