-
Notifications
You must be signed in to change notification settings - Fork 0
/
ABC340F.cpp
49 lines (49 loc) · 1.14 KB
/
ABC340F.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <bits/extc++.h>
using namespace std;
namespace pbds = __gnu_pbds;
using ui = unsigned int;
using uli = unsigned long long int;
using li = long long int;
using lli = __int128_t;
pair<lli, lli> exgcd(lli a, lli b) {
if (b == 0) return {1, 0};
pair<lli, lli> t = exgcd(b, a % b);
return {t.second, t.first - a / b * t.second};
}
ostream& operator<<(ostream& out, lli x) {
if (x < 0) cout.put('-'), x = -x;
if (x / 10) out << x / 10;
return out.put(x % 10 + '0');
}
int main(void) {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
li x, y;
cin >> x >> y;
if (y == 0) {
if (abs(x) == 1)
cout << "0 2";
else if (abs(x) == 2)
cout << "0 1";
else
cout << "-1";
} else if (x == 0) {
if (abs(y) == 1)
cout << "2 0";
else if (abs(y) == 2)
cout << "1 0";
else
cout << "-1";
} else {
lli a = -y, b = x;
lli c = -2 * b;
a *= x, b *= x; // ax+by==c
lli g = __gcd(a, b);
if (c % g != 0)
cout << "-1";
else {
pair<lli, lli> ans = exgcd(a, b);
cout << (ans.first *= c / g) << ' ' << (ans.second *= c / g);
}
}
return 0;
}