拓展欧几里得算法

· · 个人记录

#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int MAXN=1e6+5;
void Exgcd(int a,int b,int &x,int &y)
{
    if(!b) x=1,y=0;
    else
    {
        Exgcd(b,a%b,y,x);
        int t=x;
        x=y;
        y=t-a/b*y;
    }
}
int main()
{
    IO;
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,x,y;
        cin>>a>>b;
        Exgcd(a,b,x,y);
        cout<<x<<y<<endl;
    }
    return 0;
}