EXGCD

算 a mod m的逆元 转换成 a x + b y = 1 求解 x,y即可

#include<bits/stdc++.h>
using namespace std;
int xx,yy;
int exgcd(int a,int b) {
	if(b==0) {
		xx=1;
		yy=0;
		return a;
	}
	int GCD=exgcd(b,a%b);
	int tmp=xx;
	xx=yy;
	yy=tmp-a/b*yy;
	return GCD;
}
signed main() {
	ios::sync_with_stdio(false);
	int a,m;
	cin>>a>>m;
	exgcd(a,m);
	while(xx<0)xx+=m;
	yy=(1-a*xx)/m;
	cout<<xx<<" "<<yy<<"\n";
	return 1+1==3;
}
posted @ 2023-06-09 17:54  N0zoM1z0  阅读(1)  评论(0编辑  收藏  举报