#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;
}
拓展欧几里得算法
文章信息与版本
文章信息
- 发布
- 2023年8月4日
- 收录
- 2025年12月12日
- 更新
- 2026年11月15日
- 篇幅
- 约 1 分钟