First we must form the area from to . This can be achieved by the difference of A(0,r) and A(0,l). We can see it as a right angled triangle with right sides and a \cdot r, and the area is \frac{1}{2}\left ( ar^2 \right ), and for is \frac{1}{2} \left ( al^2 \right ). Thus the area is
Notice the right brackets part can be factorized (Difference of Squares) !
Now we've this equation over
Multiply both sides by \frac{2}{a}:
With a simple Number Theory principle that for any ab \le n, then a,b \le \lfloor \sqrt{n} \rfloor, thus here the same applies
. So we iterate as from 1 to \left \lfloor \sqrt{\frac{2b}{a}} \right \rfloor. Notice that (l,r) must be integers. Formally, the solution to the system
By summing the equations, we obtain r=\left ( \frac{i}{2}+\frac{b}{a\cdot i} \right ) and l=\left ( r-i \right ). We've a necessary condition to obtain an integer pair that's
Finally, append all valid pairs to a vector , sort them. If there is no valid pair, print .
Complexity is \mathcal{O}\left(\sqrt{\frac{b}{a}} \log \sqrt{\frac{b}{a}} \right) .