# An upper bound of $S_f(N)$ using Dirichlet's approximation in Analytic Number Theory by Iwaniec and Kowalski page 199

On page 199 of 'Analytic Number Theory' by Iwaniec and Kowalski, it says that by Dirichlet's approximation theorem, there exists a rational approximation to $$2\alpha$$ of type $$\Bigl|2\alpha -\frac{a}{q}\Bigr|\leq \frac{1}{2Nq}$$ with $$(a,q)=1$$ and $$1\leq q\leq 2N$$. Hence $$\|2\alpha l\|\geq \frac{1}{2}\|al/q\|$$ for any $$1\leq l with $$l\not\equiv 0\pmod q$$, and $$\sum_{\substack{1\leq l< N\\l\not\equiv 0\pmod q}} \|2\alpha l\|^{-1}\leq 2\Bigl(\frac{N}{q}+1\Bigr)\sum_{\substack{l\pmod q\\ l\not\equiv 0\pmod q}}\|l/q\|^{-1}.$$ where $$\|a\|$$ denotes the distance from $$a$$ to the nearest integer. How to deduce the above two inequalities?

The fact that $$|2\alpha - \frac{a}{q}|\leq \frac{1}{2Nq}$$ means that $$|2\alpha l - \frac{al}{q}|\leq \frac{l}{2Nq} \le \frac1{2q}$$, and so $$\|\frac{al}{q} - 2\alpha l\|\le \frac1{2q}$$. Therefore by the triangle inequality, $$\Bigl\|\frac{al}{q}\Bigr\| \le \|2\alpha l\| + \Bigl\|\frac{al}{q} - 2\alpha l\Bigr\| \le \|2\alpha l\| + \frac1{2q}.$$ The first inequality $$\|2\alpha l\|\geq \frac{1}{2}\|\frac{al}q\|$$ follows because $$\|\frac{al}q\| \ge \frac1q$$, which implies that $$\|\frac{al}q\| - \frac1{2q} \ge \frac12\|\frac{al}q\|$$.
Using the first inequality, we then have \begin{align*} \sum_{\substack{1\leq l< N\\l\not\equiv 0\pmod q}} \|2\alpha l\|^{-1} &\le \sum_{\substack{1\leq l< N\\l\not\equiv 0\pmod q}} 2 \Bigl\| \frac{al}q \Bigr\| \\ &= 2 \sum_{\substack{k\pmod q\\ k\not\equiv 0\pmod q}} \sum_{\substack{1\leq l< N\\l\equiv k\pmod q}} \Bigl\| \frac{al}q \Bigr\| \\ &= 2 \sum_{\substack{k\pmod q\\ k\not\equiv 0\pmod q}} \sum_{\substack{1\leq l< N\\l\equiv k\pmod q}} \Bigl\| \frac{ak}q \Bigr\| \\ &= 2 \sum_{\substack{k\pmod q\\ k\not\equiv 0\pmod q}} \Bigl\| \frac{ak}q \Bigr\|\#\{1\leq l< N\colon l\equiv k\pmod q\} \\ &\le 2 \sum_{\substack{k\pmod q\\ k\not\equiv 0\pmod q}} \Bigl\| \frac{ak}q \Bigr\|\Bigl(\frac{N}{q}+1\Bigr). \end{align*}