#include <bits/stdc++.h>
using namespace std;
//求a,b的最大公约数
//a*x+b*y=gcd(a,b)
//并不只是a*x+b*y=1这种类型的
int gcd(int a,int b)
{
if(b==0)
{
return a;
}
else
{
return gcd(b,a%b);
}
}
int xx;
void exgcd(int &x,int& y,int a,int b)
{
if(b==0)
{
x=1;
y=0;
return ;
}
exgcd(x,y,b,a%b);
xx=x;
x=y;
y=xx-a/b*y;
}
int main(void)
{
int a,b;
int x,y;
while(cin>>a>>b)
{
exgcd(x,y,a,b);
cout <<"x="<<x<<endl;
cout <<"y="<<y<<endl;
// cout <<gcd(a,b)<<endl;
}
cout <<"fdfsa"<<endl;
return 0;

}

C++-扩展欧几里得算法












相关文章:

  • 2021-06-20
  • 2021-10-30
  • 2021-05-26
  • 2021-09-10
  • 2021-05-30
  • 2021-05-27
  • 2022-01-13
  • 2021-05-03
猜你喜欢
  • 2022-02-15
  • 2021-06-14
  • 2021-05-10
  • 2021-06-30
  • 2022-02-24
  • 2021-10-28
相关资源
相似解决方案