跳到正文

个人记录

拓展欧几里得算法

EthanXu约 1 分钟
原文
文章信息与版本

文章信息

发布
2023年8月4日
收录
2025年12月12日
更新
2026年11月15日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#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;
}
原文
抓取于
  1. wangzhiqin

    这年头谁用扩欧啊:)