## Divisible by 3 or 7

Find the number of four-digit positive integers divisible by $3$ or $7$.
Source: NCTM Mathematics Teacher, August 2006

Solution
Consider $A=\{1002,1005,1008,\cdots,9996,9999\}$, the set of four-digit positive integers divisible by $3$ and $B=\{1001,1008,1015,\cdots,9989,9996\}$, the set of four-digit positive integers divisible by $7$. The count of $A=(9999-1002)/3+1=3000$ and the count of $B=(9996-1001)/7+1=1286$.
Some integers like $1008$ and $9996$ appear in both sets so we  subtract them as duplicates from the total count. Since $1008+(7\times 3)=1008+(3\times 7)=1029$, starting from $1008$ the duplicates occur  every $7$th integer in set $A$ or every $3$rd integer in set $B$. If we use set $A$, the count of duplicates = $(9996-1008)/(7\times 3)+1=429$. The number of four-digit positive integers divisible by $3$ and/or $7$ is $3000+1286-429=3857$.

Answer: $3857$

Alternative solution
If we divide $9999$ by $3$, we get $3333$ which means that there are $3333$ integers $\leq 9999$ that are divisible by $3$. But, if we divide $9999$ by $7$, we get $1428.43$ which is not an integer. So we say there are $1428$ integers $\leq 9999$ that are divisible by $7$. To  avoid this problem we use the floor function $\lfloor x\rfloor$ = the largest integer less than or equal to $x$ for some real number $x$. In our example, $\lfloor 1428.43\rfloor=1428$.
Number of four-digit integers divisible by $3$
$\lfloor 9999/3\rfloor-\lfloor 999/3\rfloor=3000$
Number of four-digit integers divisible by $7$
$\lfloor 9999/7\rfloor-\lfloor 999/7\rfloor=1286$
Number of four-digit integers divisible by $21$
$\lfloor 9999/21\rfloor-\lfloor 999/21\rfloor=429$
There are $3000+1286-429=3857$ four-digit integers divisible by $3$ and/or $7$.