#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
void gcd(LL a, LL b, LL &d, LL &x, LL &y)
{
if(!b)
{
d = a;
x = 1;
y = 0;
}
else
{
gcd(b, a % b, d, y, x);
y -= x * (a / b);
}
}
int main()
{
std::ios::sync_with_stdio(false);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
LL a, b;
LL x, y;
while(cin >> a >> b)
{
LL x, y, d;
gcd(a, b, d, x, y);
if(d != 1)
cout << "sorry" << endl;
else
{
while(x < 0)
{
x += b;
y -= a;
}
cout << x << " " << y << endl;
}
}
}
原文:https://www.cnblogs.com/KeepZ/p/11342116.html