解释以及解的过程:http://blog.sina.com.cn/s/blog_59825cee0100la9u.html
整理的模板:
hdu 2669这个题规定了n==1;
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
#define ll long long
using namespace std;
ll exgcd(ll a, ll b, ll &x, ll &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
ll r=exgcd(b,a%b,x,y),t;
t=x;
x=y;
y=t-(a/b)*y;
return r;
}
int main()
{
ll a,b,x,y;
while(cin>>a>>b)
{
ll g=exgcd(a,b,x,y);
if(g==1) //n=1;
{
if(x>=0)printf("%lld %lld\n",x,y);
else printf("%lld %lld\n",(x%b+b)%b,(y%a-a)%a);
}
else
puts("sorry");
}
}