extended euclidean algorithm

#include<bits/stdc++.h>
using namespace std;
int ex_gcd(int a,int b,int& x,int& y)
{
	int t,res;
	if(!b)
	{
		x=1;y=0;return a;
	}
	else
	{
		res=ex_gcd(b,a%b,x,y);
		t=x;
		x=y;y=t-a/b*y;
		return res;
	}
}
int main()
{
	int a,b,x,y;
	a=60;
	b=22;
	cout<<ex_gcd(a,b,x,y)<<endl;
	cout<<x<<" "<<y<<endl;
	return 0;
}
发布了13 篇原创文章 · 获赞 0 · 访问量 189

猜你喜欢

转载自blog.csdn.net/qq_43737697/article/details/104024633