Let $a$ be a natural number such that the number of different prime divisors of $a$ is $2$. For example $6=2\times 3$, or $12=2^2\times 3$ or $225=3^2\times 5^2$.
Now find the number all $a$ less than 1000?
My attempt: we must use of the prime numbers $2,3,5,7,11,13,17,19,23,29,31$
Iterate $p$ downward starting from the highest prime below $500$. Iterate $k$ from $1$ to $\log_p(500)$. Iterate $q$ from $2$ up through primes less than $\frac{1000}{p^k}$. Iterate $j$ from $1$ to $\log_q(1000/p^k)$.
This captures all $p^kq^j$ that are less than $1000$.