Solution to a problem CF7C Line

Although I have not been in Los Valley

0.0..jpg

However, I had a (funny in CF

Subject to the effect

To the equation \ (Ax of + By + C = 0 \) . Wherein \ (A \) , \ (B \) , \ (C \) is known, find \ (X \) , \ (Y \) .

\(Idea\)

Expand the template title Euclidean algorithm.

The algorithm determined linear equation \ (Ax + By = gcd ( A, B) \)

Then, this equation can be converted:

\[Ax + By = gcd(A, B)\]

\[\to Ax + By = -\frac{C}{z}, -\frac{C}{z}= gcd(A, B)\]

\ [\ To Ax \ AST + By \ AST = C \]

Where \ (the X-\) , \ (the y-\) may be obtained by expanding the Euclidean algorithm,

Then, we simply requires the \ (Z \) , and \ (Z = - \ {C} {FRAC GCD (A, B)} \) ;

Therefore, the final answer \ (X = X \ AST - \ FRAC {C} {GCD (A, B)} \) , \ (Y = Y \ AST - \ FRAC {C} {GCD (A, B)} \ ) ;
_____
given below template to expand Euclid

inline int ecgcd(int a,int b,int &x,int &y){
    if(!b) {x=1; y=0; return a;}
    int d=exgcd(b,a%b,x,y);
    int z=x; x=y; y=z-y*(a/b);
    return d;
}

\ (AC \) program to write their own

Guess you like

Origin www.cnblogs.com/cbyyc/p/11441309.html