Extended Euclid summary

https://blog.csdn.net/destiny1507/article/details/81750874

#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int exgcd(int a,int b,int &x,int &y)
{
    if(b == 0){
        x = 1; y = 0;
        return a;
    }
    int r = exgcd(b, a % b, x, y);
    int temp = y;
    y = x - (a / b) * y;
    x = temp;
    return r;
}
int main()
{
    int a, b;
    cin >> a >> b;
    int x, y;
    int d = exgcd(a, b, x, y);
    cout << x << " " << y << " " << d << endl;
    return 0;
}

Guess you like

Origin www.cnblogs.com/solvit/p/11432724.html