#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
LL gcd(LL a, LL b)
{
return b ? gcd(b,a%b) : a;
}
void exgcd(LL a ,LL b,LL &x ,LL &y)
{
if(b==0)
{
x=1;
y=0;
return ;
}
exgcd(b,a%b,x,y);
LL tmp=x;
x=y;
y=tmp-(a/b)*y;
}
int main()
{
LL a,b;
while(~scanf("%lld%lld",&a,&b))
{
LL w=gcd(a,b);
if(w!=1)
printf("sorry\n");
else
{
LL x,y;
exgcd(a,b,x,y);
x=(x%b+b)%b;
y=(1-a*x)/b;
printf("%lld %lld\n",x,y);
}
}
return 0;
}
HDU 2669 扩展欧几里得
最新推荐文章于 2015-08-03 22:27:49 发布