扩展欧几里得算法简单推导
给定a,b,扩展欧几里得算法求得最大公约数的同时,还会给出ax+by=gcd(a,b)的整数解x,y
假设
\[d_{i-2}=d_{i-1} c_i+d_i
\\
d_{i-1}=d_ic_{i+1}+d_{i+1}
\]
假设a,b的最大公约数为\(g\),当某一步的\(d_{i-1}=0\)时,\(1*d_{i-2}+0*d_{i-1}=g=d_{i-2}\) (递归的终点),对任意步骤,如下更新x和y,
\[xd_{i-1}+yd_i=g
\\
xd_{i-1}+y(d_{i-2}-d_{i-1}c_i)=g
\\
yd_{i-2}+(x-c_i y)d_{i-1}=g
\\
yd_{i-2}+(x-\frac{d_{i-2}}{d_{i-1}} y)d_{i-1}=g
\]
所以
\[x'=y
\\
y'=x-\frac{d_{i-2}}{d_{i-1}}y
\]