Extended Euclidean Algorithm
Submissions: 89   Accuracy:

52.82%

  Difficulty: Basic   Marks: 1

We already know Basic Euclidean Algorithm. Now using Extended Euclidean Algorithm, Calculate the GCD and integer coefficients x, y using the same. x and y must satisfy the equation ax + by = gcd(a, b) 

Input:
The first line of input contains integer T denoting the numer of testcases.T testcases follow. Each testcase contains one line on input containing two numbers a and b.

Output:
For each testcase, in a new line, print the GCD g for a, b, integer coefficients x, y calculated using Extended Euclidean Algorithm.

Constraints:
1 <= T <= 103
1 <= a, b <= 106

Example:
Input:

1
35 15
Output:
5 1 -2

** For More Input/Output Examples Use 'Expected Output' option **

Author: SIDG


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.