https://mirror.codeforces.com/problemsets/acmsguru/problem/99999/106 can someone please help me solve this?
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3611 |
| 4 | jiangly | 3583 |
| 5 | strapple | 3515 |
| 6 | tourist | 3470 |
| 7 | Radewoosh | 3415 |
| 8 | Um_nik | 3376 |
| 9 | maroonrk | 3361 |
| 10 | XVIII | 3345 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 162 |
| 2 | adamant | 148 |
| 3 | Um_nik | 146 |
| 4 | Dominater069 | 143 |
| 5 | errorgorn | 141 |
| 6 | cry | 138 |
| 7 | Proof_by_QED | 136 |
| 8 | YuukiS | 135 |
| 9 | chromate00 | 134 |
| 10 | soullless | 133 |
https://mirror.codeforces.com/problemsets/acmsguru/problem/99999/106 can someone please help me solve this?
| Name |
|---|



Note that if $$$\gcd(a, b) \not\mid c$$$, no solution exists. Otherwise, divide $$$a, b, c$$$ by this $$$\gcd$$$, now we assume $$$\gcd(a, b) = 1$$$.
Let $$$x_0, y_0$$$ be any integer solution of the equation (which can be found using Euclid's algorithm).
One can prove that all solutions of the equation must be of the form $$$(x_0 - b n, y_0 + a n)$$$ for some integer $$$n$$$.
Now, we end up with the problem of counting integer $$$n$$$ such that $$$x_1 \le x_0 - b n \le x_2$$$, $$$y_1 \le y_0 + a n \le y_2$$$.
This can be done by just getting min and max bounds on $$$n$$$ using the above inequalities. Make sure to take care of all the cases such as $$$a = 0$$$, $$$a \lt 0$$$, when the upper bound is less than the lower bound, etc..
how to find the bounds?
If $$$b \gt 0$$$, you have
If b < 0, the inequalities are reversed.
You similarly get another relation from the other inequality.
Take note of the fact that what I have written above is real division, not integer division.
You can take reference from CP-algorithms's tutorial on Linear Diophantine Equations. They have the exact solution. There are a lot of edge cases to consider like if a == 0 or b == 0 etc, or a < 0 or b < 0.