exgcd,求乘法逆元


  LL exgcd(LL x,LL y){
      printf("%lld %lld\n",x,y);
      if (y==0){
        xx=1;yy=0;return(x);    
    }
    LL ret=exgcd(y,x%y);
    LL t=xx;xx=yy;yy=t-(x/y)*yy;
    return(ret);
  }
 procedure exgcd(a,b:int64);
  var
   t:longint;
    begin
      if  b=0 then
        begin
          x:=1;y:=0;
          exit;
        end else
       exgcd(b,a mod b);
       t:=x;x:=y;y:=t-(a div b)*y;
    end;
 
  function cfny(a:int64):int64;
  var
    b:longint;
     begin
       b:=zs;
       exgcd(a,b);
       cfny:= ((x mod zs)+zs) mod zs;
     end;
posted @ 2016-03-18 10:43  z1j1n1  阅读(363)  评论(0编辑  收藏  举报