其他分享
首页 > 其他分享> > 扩展欧几里德板子

扩展欧几里德板子

作者:互联网

#include <bits/stdc++.h>
using namespace std;

int a,b;
int x,y,d;

int exgcd(int a,int b,int& x,int& y){
	if(b==0) {x=1,y=0; return a;}
	int d=exgcd(b,a%b,x,y);
	int z=x; x=y; y=z-y*(a/b);
	return d;
}

int main(){
	// ios::sync_with_stdio(0);
	freopen("1.in","r",stdin);
	freopen("1.out","w",stdout);
// ==============================================================
	cin>>a>>b;
	d=exgcd(a,b,x,y);
	printf("x=%d\ny=%d\ngcd(x,y)=%d",x,y,d);
	
// ==============================================================	
end:
	return 0;
}

标签:return,stdout,int,ngcd,欧几里德,扩展,exgcd,板子,freopen
来源: https://www.cnblogs.com/syqwq/p/15375717.html