扩展欧几里得能快速解a*x+b*y=gcd(a,b)。
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int extgcd(int a,int b,int &x,int &y)
{
int d=a;
if(b!=0)
{
d=extgcd(b,a%b,y,x);
y-=(a/b)*x;
}
else
{
x=1;
y=0;
}
return d;
}
int main()
{
freopen("in.txt","r",stdin);
int t;
cin>>t;
while(t--)
{
int a,b;
cin>>a>>b;
int x,y;
extgcd(a,b,x,y);
cout<<x<<y<<endl;
}
return 0;
}