Hide

Problem A
Extended GCD

Languages en is

Implement an algorithm to find the greatest common divisor of two integers a and b, often denoted by gcd(a,b).

Input

Input is two lines. The fyrst line contains the integer a. The second line contains the integer b.

Output

Output three lines. The first line should contain the integer g, where g=gcd(a,b) and g=ua+vb. The second line should contain the integer u. The third line should contain the integer v.

Scoring

Group

Points

Constraints

1

60

1a,b1018.

2

20

0a,b1018.

3

20

0a,b1018, u>0 and u should be minimized.

Sample Input 1 Sample Output 1
6
15
3
-2
1
Sample Input 2 Sample Output 2
4
0
4
1
0
Sample Input 3 Sample Output 3
6
15
3
3
-1
Hide

Please log in to submit a solution to this problem

Log in