#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int M=1e5+20;
long x,y;
long gcd(long a,long b)
{
if(a%b==0)
return b;
else
{
return gcd(b,a%b);
}
}
void extgcd(long a,long b)
{
if(b==0)
{
x=1;
y=0;
}
else
{
extgcd(b,a%b);
int tmp;
tmp=x;
x=y;
y=tmp-(a/b)*y;
}
}
int main()
{
long a,b;
while(cin>>a>>b)
{
//求 求ax+by=1中的最小正数x
long d=gcd(a,b);
if(d!=1)
cout<<"sorry"<<endl;
else
{
extgcd(a,b);//求出特解
int i=1;
//通解为
//x=x0+(b/d)*n y=y0-(a/d)*n
while(x<0)
{
x+=(b/d)*i;
y-=(a/d)*i;
}
cout<<x<<" "<<y<<endl;
}
}
return 0;
}
hdu 2669 exgcd(水)
最新推荐文章于 2018-08-14 15:10:00 发布