409039: GYM103426 C Equation
Description
Azat wondered how many pairs of integer roots $$$(x_1, x_2)$$$ of the quadratic equation $$$x^2 + bx + c = 0$$$ exist, when the sum of coefficients $$$b$$$ and $$$c$$$ is between $$$l$$$ and $$$r$$$, that is, $$$l \le b + c \le r$$$ ($$$b$$$, $$$c$$$, $$$l$$$, $$$r$$$ are all integers). Pairs of roots $$$(x_1, x_2)$$$ and $$$(x_2, x_1)$$$ are considered the same.
Help Azat find out the answer to his problem.
InputThe first line contains two integers $$$l$$$ and $$$r$$$ ($$$-10^{12} \le l \le r \le 10^{12}$$$; $$$r - l \le 10^6$$$).
OutputPrint a single number — the number of pairs of integer roots, if there are an infinite number of pairs of integer roots, print -1.
ScoringSubtask | Score | Constraints |
$$$1$$$ | $$$8$$$ | $$$l = r$$$ and $$$|l| \le 10^3$$$ |
$$$2$$$ | $$$9$$$ | $$$r - l \le 2 \cdot 10^3$$$ and $$$|l|, |r| \le 10^3$$$ |
$$$3$$$ | $$$13$$$ | $$$l = r$$$ and $$$|l| \le 10^6$$$ |
$$$4$$$ | $$$20$$$ | $$$r - l \le 2 \cdot 10^2$$$ and $$$|l|, |r| \le 10^{8}$$$ |
$$$5$$$ | $$$16$$$ | $$$l = r$$$ and $$$|l| \le 10^{12}$$$ |
$$$6$$$ | $$$34$$$ | $$$r - l \le 10^6$$$ and $$$|l|, |r| \le 10^{12}$$$ |
7 7Output
4Input
-2 -2Output
1Input
-7 -3Output
13Note
For $$$l = r = 7$$$, there are four pairs of roots: $$$(2, 9), (0, -7), (3, 5), (-1, -3)$$$.
For the 2 and 9 pair, the equation is $$$x^2 - 11 \cdot x + 18 = 0$$$.
For the 0 and -7 pair, the equation is $$$x^2 + 7 \cdot x + 0 = 0$$$.
For the 3 and 5 pair, the equation is $$$x^2 - 8 \cdot x + 15 = 0$$$.
For the $$$-1$$$ and $$$-3$$$ pair, the equation is $$$x^2 + 4 \cdot x + 3 = 0$$$.
In all four cases, the sum of $$$b$$$ and $$$c$$$ is equal to $$$7$$$.