/*************************************************************************
> File Name: extend_gcd.cpp
> Author: wangzhili
> Mail: wangstdio.h@gmail.com
> Created Time: 2014年03月17日 星期一 20时47分53秒
************************************************************************/
#include<iostream> //求GCD(a, b), 同时求解满足条件的x, y, ax + by = GCD(a, b);
using namespace std;
int extend_gcd(int a, int b, int &x, int &y){
if(b == 0){
x = 1, y = 0;
return a;
}else{
int r = extend_gcd(b, a%b, y, x);
y -= x*(a/b);
return r;
}
}
int main(){
int a, b, x, y;
while(cin >> a >> b){
int ans = extend_gcd(a, b, x, y);
cout << ans << " " << x << " " << y << endl;
}
return 0;
}
转载于:https://www.cnblogs.com/wangzhili/p/3950309.html