exgcd板子

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

求a在模b意义下的乘法逆元

void exgcd(int &x,int &y,int a,int b)
{
    if(!b)
    {
        x=1;
        y=0;
        return;
    }
    exgcd(x,y,b,a%b);
    int t=x;
    x=y;
    y=t-a/b*y;
}
int inv(int a,int b){
    int x,y;
    exgcd(x,y,a,b);
    x=(x%b+b)%b;
    return x;
}
posted @ 2025-10-23 23:01  Marinaco  阅读(2)  评论(0)    收藏  举报
//雪花飘落效果