I’ve been playing around with wheel factorization (Wikipedia link) and wanted to know how many spokes there are in a given wheel. For a 2-7 wheel the circumference of this would be 210 and then I can count the multiples of 2, 3, 5 and 7 (without recounting overlapping multiples) between 11 to 210 to get the answer of 162 spokes for this wheel. Knowing this also tells me the number of gaps: 210 - 162 = 48 gaps in the wheel.
However, this method of just counting up every multiple quickly becomes impractical. For a 2-31 wheel I’d have to count every multiple of 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 and 31 between 37 and 200560490130. How can I calculate the spokes for a given wheel easily?
To do this, you can use the principle of inclusion and exclusion (PIE), though it doesn't work for large $n$. This states: $$\Biggl|\bigcup_{i=1}^n A_i\Biggr| = \sum_{k = 1}^{n} (-1)^{k+1} \left( \sum_{1 \leq i_{1} < \cdots < i_{k} \leq n} \left| A_{i_{1}} \cap \cdots \cap A_{i_{k}} \right| \right)$$
I will write it out for $n=2,3$ and compute the number of multiples.
For 2: $P(A \cup B) = P(A)+P(B) - P(A \cap B)$.
Now we have that there are $6/2=3$ multiples of $2$, $6/3=2$ multiples of $3$ and $6/(2\cdot3)=1$ multiples of $2\cdot3$, so in total we have $3+2-1=4$ multiples of either 3 or 2.
For 3: $P(A \cup B) = P(A)+P(B)+P(C) - P(A \cap B)- P(A \cap C) \\ - P(B \cap C)+P(A \cap B \cap C)$
$$30/2+30/3+30/5-30/6-30/10-30/15+30/30 = 22$$