#include<cstdio>
#include<iostream>
#include<algorithm>
typedef __int64 LL;
using namespace std;
LL gcd(LL a,LL b)
{
return b==0?a:gcd(b,a%b);
}
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()
{
LL a,b;
while(~scanf("%I64d%I64d",&a,&b))
{
if(gcd(a,b)!=1)
{
printf("sorry\n");
continue;
}
LL x=0,y=0;
LL d=1;
gcd(a,b,d,x,y);
while(x<0)
{
x+=b;
y-=a;
}
printf("%I64d %I64d\n",x,y);
}
return 0;
}
hdu 2669 扩展欧几里得
最新推荐文章于 2019-03-24 23:46:08 发布