Number of terms of the form $2^a\times 3^b$ 
I need to find the exact number of terms between $L$ and $R$ of the form $ 2^a\times 3^b $, where $a$ and $b$ follow the criteria $a
\gt 0 $ and  $b\ge 0$. 

I couldnt solve this question so could anyone help me out here.
Suppose given a range $(2, 8)$ the number of terms of the form $2^a\times 3^b $ is $4$, i.e. $2,4,6,8$.
Help me out to get any direct formula for getting this number of terms.
 A: You are looking for the number of pairs $(a,b)$ such that $\log L \le a\log 2 + b\log 3 \le \log R$.  If the numbers are small, you can compute the maximum $b$ as $\frac {\log R}{\log 3}$, then loop from $0$ to that, compute the range of acceptable $a$'s for each and add them up.  I don't know of another exact approach.  If you are going to do it on a computer you have to worry about floating point errors if $L$ or $R$ can be of the form $2^a3^b$, as the test might come out wrong in floating point as the $\log$ function and the arithmetic operations are not exact.  
If an approximate answer is acceptable and the numbers are large, you can imagine a square lattice with the powers of $2$ going horizontally and powers of $3$ going vertically.  The number of lattice points with $2^a3^b \le R$ are the ones below the line going through $(\frac {\log R}{\log 2},0)$ and $(0,\frac {\log R}{\log 3})$.  The area of this triangle is $\frac 12\frac{(\log R)^2}{\log 2 \cdot \log 3}$ and a similar argument about the ones you lose to the lower limit gives an estimate of $\frac 12\frac{(\log R)^2-(\log L)^2}{\log 2 \cdot \log 3}$
