拓展欧几里得

int gcd(int a,int b){
return b==0? a:gcd(b,a%b) }

int exgcd(int a,int b,int &x,int &y){
if(b==0){  x=1,y=0; return a}

int  d=exgcd(b,a%b,x,y)t=x, x=y ; y=t-(a/b)*x;   return d;

}

void exgcd(int a,int y,int &x,int &y)

{

  if(b==0){ x=1,y=0;return ;}

  exgcd(b,a%b,y,x);

  y-=(a/b)*x;
}

https://zhuanlan.zhihu.com/p/378728642

posted @ 2024-06-29 08:01  JMXZ  阅读(0)  评论(0编辑  收藏  举报