Welcome To SDIBT ACM-ICPC Online Judge

VIRTUAL JUDGE Recent Contest F.A.Qs Forum Home ProblemSet Status Ranklist Contest LoginRegister Exam
Problem 1064. -- Euclid problem

Euclid problem

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 17  Solved: 12


From Euclid, it is known that for any positive integers A and B there exist such integers X and Y that AX + BY = D, where D is the greatest common divisor of A and B. The problem is to find the corresponding X, Y, and D for a given A and B.


The input will consist of a set of lines with the integer numbers A and B, separated with space ( A, B < 1, 000, 000, 001).


For each input line the output line should consist of three integers X, Y, and D, separated with space. If there are several such X and Y, you should output that pair for which X<=Y and | X| + | Y| is minimal.

Sample Input

4 6
17 17

Sample Output

-1 1 2
0 1 17





한국어 中文 English
All Copyright Reserved 2008-2010 SDIBT TEAM
GPL2.0 2003-2010 HUSTOJ Project TEAM
Anything about the Problems, Please Contact Admin:admin