Numbers up to 1000 divisible by 2 or 3 and no other prime My task requires to find all numbers from $1-1000$ such that they are divisible by $2$ or $3$ and no other primes. I know that $2$ divides even numbers and I can use the formula $\left \lfloor{\frac{1000}{2}}\right \rfloor $ and the numbers divisible by three $\left \lfloor{\frac{1000}{3}}\right \rfloor $. Also we rule out the numbers that are divisible by both, so by $6$ $\left \lfloor{\frac{1000}{6}}\right \rfloor $. In total we get that there are $500+333-166=667$ numbers divisible by $2$ or $3$. However I also need to make sure that I $\textit{only}$ count numbers divisible by either of these $2$. Is there a quick way to do it?

Such a number should be in the form of $2^m3^n$ where $m$ and $n$ are non-negative integers such that $m$ and $n$ are not both zero.
If $n=0$, $m\ge1$ and $2^m\le1000$. So $1\le m\le 9$.
If $n=1$, $2^m\le\frac{1000}{3}$. So $0\le m\le 8$.
If $n=2$, $2^m\le\frac{1000}{9}$. So $0\le m\le 6$.
If $n=3$, $2^m\le\frac{1000}{27}$. So $0\le m\le 5$.
If $n=4$, $2^m\le\frac{1000}{81}$. So $0\le m\le 3$.
If $n=5$, $2^m\le\frac{1000}{243}$. So $0\le m\le 2$.
If $n=6$, $2^m\le\frac{1000}{729}$. So $m= 0$.
If $n=7$, $2^m\le\frac{1000}{2187}$, which is impossible.
Number of possibilities is $9+9+7+6+4+3+1=39$.
