P1082 同余方程

link

 

 题解可参考:https://www.luogu.com.cn/blog/cicos/solution-p1082#

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


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

int main(){
    scanf("%lld %lld", &a, &b);
    exgcd(a,b);
    x=(x%b+b)%b;
    printf("%lld", x);
    return 0;
}

 

posted @ 2020-03-29 17:11  feibilun  阅读(109)  评论(0编辑  收藏  举报