欧几里得拓展

时间:2020-12-05 05:18:54
#include<iostream>
using namespace std;
long long x,y,g;
long long ex_gcd(long long a,long long b)
{
    if(b==0)
    {
        x=1;y=0;g=a;
    }
    else
    {
        ex_gcd(b,a%b);
        long long t=x;
        x=y;
        y=t-a/b*y;
    }
}
int main()
{
    int a,b;
    cin>>a>>b;
    ex_gcd(a,b);
    cout<<x<<" "<<y<<" "<<g<<" "<<endl;/*x和y是特解,g为a、b的最大公约数*/ 
} 
/*
通解
x=x1(特解)+b/g*k;
y=y1(特解)-a/g*k;
k为正整数*/