1632:【 例 2】[NOIP2012]同余方程

#include<bits/stdc++.h>
#define ll long long
using namespace std;
void Exgcd(ll a,ll b,ll &d, ll &x,ll &y)
{
    if(!b)
    {
        d=a;
        x=1;
        y=0;
    }
    else
    {
        Exgcd(b,a%b,d,x,y);
        int t=x;x=y;y=t-a/b*y;
    }
}
int main()
{
    ll a,b,d,x,y;
    scanf("%lld%lld",&a,&b);
    Exgcd(a,b,d,x,y);
    printf("%lld",(x%b+b)%b);
    return 0;
}

1632:【 例 2】[NOIP2012]同余方程

posted @ 2019-08-24 16:35  Gold_stein  阅读(216)  评论(0编辑  收藏  举报