首页 > 其他 > 详细

扩展欧几里得

时间:2018-01-14 10:29:19      阅读:263      评论:0      收藏:0      [点我收藏+]
#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;
}

 

扩展欧几里得

原文:https://www.cnblogs.com/Culion-BEAR/p/8282292.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!