题目
代码
cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL ex_gcd(LL a, LL b, LL &x, LL &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
LL gcd = ex_gcd(b, a % b, x, y);
LL temp;
temp = x;
x = y;
y = temp - a / b * y;
return gcd;
}
int main()
{
LL a, b;
while (scanf("%lld %lld", &a, &b) == 2)
{
LL x, y;
LL gcd = ex_gcd(a, b, x, y);
if (gcd != 1)
{
cout << "sorry\n";
continue;
}
x = (x % b + b) % b;
y = (1 - a * x) / b;
printf("%ld %ld\n", x, y);
}
}