首页 > 其他 > 详细

拓展欧几里得

时间:2017-07-20 20:38:20      阅读:180      评论:0      收藏:0      [点我收藏+]

 

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

void exgcd(int a,int b,LL &x,LL &y){
    if(b==0){x=1, y=0; return;}
    LL tx,ty;
    exgcd(b,a%b,tx,ty);
    x=ty;
    y=tx-(a/b)*ty;
}

int main(){
    LL a,b,x,y;
    cin>>a>>b;
    exgcd(a,b,x,y);
    x=(x%b+b)%b;
    cout<<x<<endl;
    return 0;
}

拓展欧几里得

原文:http://www.cnblogs.com/codetogether/p/7214140.html

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