So here's a simple question that I encountered and I am failing to grasp why this way to solve the question works. The question is as follows: Set A contains numbers $\{1+3d,d\geq0 \}$ and set B contains numbers $\{9+7m,m\geq 0\}$. How many elements are in the union of the first $2004$ terms in each set? I solved this question using linear congruences, but to my surprise there exists a simple solution, here is how it begins:
Shift down the first sequence by $1$ and the second by $9$ so that the two sequences become $0,3,6,\cdots,6009$ and $0,7,14,\cdots,14028$. The first becomes multiples of $3$ and the second becomes multiples of $7$. Their intersection is the multiples of $21$ up to $6009$..........
How does this work? It doesn't make sense to me intuitively, since suppose I want the union of set $\{1\}$ and $\{9\}$, using the method above I would get $1$ term but the answer is actually $2$.