exgcd
ProzacPainkiller
·
·
个人记录
\text{设整数 }x\text{ 和 }y\text{ 使得 }ax+by=\gcd(a,b),\text{求 } x,y
\text{设 }a'=b,b'=a\text{ mod } b,x',y',\text{使得 }a'x'+b'y'=d
\text{当 }b'=0\text{ 时},\text{可得 }a'=\gcd(a,b)
\therefore\text{此时 }x'=1,y'=0
a'x'+b'y'=d
\therefore bx'+(a\text{ mod }b)y'=d
\therefore bx'+(a-b[a/b])y'=d
\therefore bx'+ay'-b[a/b]y'=d
\therefore ay'+b(x'-[a/b]y')=d
\therefore x=y',y=x'-[a/b]y'