扩展欧几里得

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <set>
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 t=*x;*x=*y;*y=t-a/b*(*y);
    return r;
}

int main(){
    int a,b,x,y;
    cin>>a>>b;
    cout<<exGcd(a,b,&x,&y)<<endl;
    cout<<x<<" "<<y<<endl;
}

 

posted @ 2018-01-14 06:13  痞子熊  阅读(127)  评论(0编辑  收藏  举报