No. of solutions to a integer-based inequality 
*

*Let $p, q$ be positive integers such that $q≤99$. Find number of ordered pairs $(p,q)$ such that $$\frac {2}{5} \ < \frac {p}{q} \ < \ \frac {21}{50}. $$
Here's what I could do:
Using the fact that if  $ 0 \ < \frac {a}{b} < 1  \ \Rightarrow  \frac {a}{b}  \ < \  \frac {a+d}{b+d} $
where $d>0, $   I could find a few solutions like $(p,q) \ = (41,99) \ (40,98) \, (39,96), \ etc. $ But it seems like there are a lot more possible solution pairs.
What should be a proper strategy?
Any hint or help will be much appreciated. Thanks.
 A: Hint: $q \leq 99$ and
$$\frac{p}{q} < \frac{21}{50}$$
with $q$ positive imply that
$$p < \frac{21q}{50} \leq \frac{21 \cdot 99}{50} = 41.58$$
which further means that
$$p \leq 41.$$
Can you finish?
A: After rearranging you can see that $\dfrac{2q}{5} < p < \dfrac{21q}{50}$
so there must be an integer between
$\dfrac{2q}{5}$ and $\dfrac{21q}{50}$and also their difference $= \dfrac{q}{50} < 2$ so their can't be more than 2 integers.
So solve the equations $$ \begin{align} 
\left\lfloor\dfrac{21q}{50} \right\rfloor - \left\lfloor\dfrac{2q}{5}  \right\rfloor &= 1\\
\left\lfloor\dfrac{21q}{50} \right\rfloor - \left\lfloor\dfrac{2q}{5}  \right\rfloor &= 2 \end{align} $$
And then you multiply by the 2 the number of solutions to the second and add that to the first
A: Here's another approach.
$$Z=\sum_p\sum_{1 \le q < 100} [2/5 < p/q < 21/50]$$
can be rewritten as
$$Z=\left(\sum_p\sum_{1 \le q < 100} [p < 21q/50]\right) - \left(\sum_p\sum_{1 \le q < 100} [p \le 2q/5]\right)$$
And $p < 21q/50$ is the same as $p \le 21q/50$ except when $50|q$, so both sums are effectively the same problem.
So generalizing (and assuming s,t coprime):
$$\begin{array}{rcl}
f(s, t, n) 
&=& \sum_{0 \le q < nt} \sum_p[p \le sq/t]
\\ &=& \sum_{0 \le q < nt} \lfloor sq/t \rfloor + 1
\\ &=& nt + \sum_{0 \le r < t} \sum_{0 \le q < n} \lfloor s(qt + r)/t \rfloor
\\ &=& nt + \sum_{0 \le r < t} \sum_{0 \le q < n} sq + \lfloor sr/t \rfloor 
\\ &=& nt + st\frac{n^2-n}{2} + n\sum_{0 \le r < t} \lfloor sr/t \rfloor 
\\ &=& nt + st\frac{n^2-n}{2} + n\sum_{0 \le r < t} \frac{sr - (sr \mod t)}{t}
\\ &=& nt + st\frac{n^2-n}{2} + \frac{n}{t}(s\frac{t^2-t}{2} - \frac{t^2-t}{2})
\\ &=& \frac n2 (nst + t - s + 1)
\end{array}$$
That for s,t coprime $$(\sum_{0 \le r < t} {sr \mod t}) = (t^2 - t)/2$$ is exploiting the neat property that for the function $g(r) = (sr \mod t)$, the image of ${0 .. t-1}$ is exactly ${0 .. t-1}$, that is, it is a permutation.
The lowerbound for the Z sums isn't $0\le q$, it's $1 \le q$; so we need to subtract the $q=0$ term from the sums.  So the solution is
$$Z = f(21, 50, 2) - f(2, 5, 20) - \underbrace{100/50}_\text{(a)} - \underbrace{(0 - 1)}_\text{(b)} = 89$$
(a) Correction for the $50|q$ terms in the first sum
(b) Correction for the $q=0$ case in both sums
