I was so going to test a dish.
I have no mind to maintain a blog. Open a blog post now. You may remember mess.
This may be my last blog post of the OI career? ?
Certainly very, very long.
impossible. Who knows when I'll restore the mentality of the above two sentences deleted at the beginning of the blog in various Hu Lie Lie.
- "Columns" solution to a problem: exgcd
Nest planted. Honestly I see $ exgcd $ a. Also written out. But do not use flawed.
$ Exgcd $ primarily used to solve linear equations $ ax + $ solutions of a group of specialized gcd (a, b) by =. This particular solution can be extended to our group $ ax + by = c $ in. The PEI Shu theorem, if and only if $ gcd (a, b) | C $ time, equation $ ax + by = c $ solvable.
$ Exgcd $ proof:
For equation $ ax + by = gcd (a, b) $, so $ a = b, b = a% b $, there are $ b * x + a% b * y = gcd (b, a% b) $ ,
又$gcd(a,b)=gcd(b,a%b)$,所以可得$a*x+b*y=b*x+a%b*b=b*x+(a-a/b*b)*y=a*y+b*(x-a/b*y)$
Proved.
Code:
int exgcd(rint a,rint b,rint &x,rint &y) { if(!b) { x = 1; y = 0; return a; } rint res=exgcd(b,a%b,x,y); rint t=x;x=y;y=t-a/b*x; return res; }
This question about the number of columns, we need to apply in advance $ exgcd $ solve a particular solution set. Our ultimate goal is that the + abs (y) $ minimum, so that when we assume obtain $ a <b $, then the answer must be made positive or negative maximum value at the minimum $ x $ $ abs (x). If $ a> b $, $ swap $ then be resolved.