exgcd 解同余方程ax=b(%n)
ax=n(%b) -> ax+by=n
方程有解当且仅当 gcd(a,b) | n ( n是gcd(a,b)的倍数 )
exgcd解得 a*x0+b*y0=gcd(a,b)
记k=n/gcd(a,b)
则方程ax+ny=b的所有解为
x=k*x0 + [ b/gcd(a,b) ]*t
y=k*y0 - [ a/gcd(a,b) ]*t
a*x0+b*y0=gcd(a,b)
-> (a*x0+b*y0)*n/gcd(a,b) = gcd(a,b)*n/gcd(a,b)
-> x=k*x0,y=k*y0是方程ax+by=n的基本解
->ax+by + lcm(a,b)*t-lcm(a,b)*t = n (lcm(a,b)=a*b/gcd(a,b))
->a*[ x+[ b/gcd(a,b) ]*t ] + b*[ y- [ a/gcd(a,b) ]*t ] =n
n/gcd
x