`{"id":"f40285c3-3a48-4ab8-bda0-a6537490bd1a","name":"Extended Euclidean Algorithm","description":"You have been given two Integers a and b. you need to find an integral solution of x and y such that a*x + b*y= gcd(a,b).\r\nIt can be proven that solution always exist.","inputFormat":"The first line contains 2 integer a and b","outputFormat":"output integral value of x and y in a single line.","constraints":"1 &lt;= a, b &lt;= 10^6","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.util.Scanner;\r\n\r\npublic class Main {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\r\n\t}\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"","sampleOutput":"","questionVideo":"https://www.youtube.com/embed/H4AuhS7pN48","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"086949fa-3c5e-40c6-8a9c-f9be4b400318","name":"Number Theory For Experts","slug":"number-theory-for-experts","type":0},{"id":"5d1351ed-560a-4694-92f6-1e52560161ac","name":"Extended Euclidean Algorithm","slug":"extended-euclidean-algorithm","type":1}],"next":{"id":"494d08e9-b9e3-459b-9395-9a9de36aa28c","name":"Linear Diophantine Equation","type":1,"slug":"linear-diophantine-equation"},"prev":null}}`

# Extended Euclidean Algorithm

You have been given two Integers a and b. you need to find an integral solution of x and y such that a*x + b*y= gcd(a,b). It can be proven that solution always exist.

`{"id":"f40285c3-3a48-4ab8-bda0-a6537490bd1a","name":"Extended Euclidean Algorithm","description":"You have been given two Integers a and b. you need to find an integral solution of x and y such that a*x + b*y= gcd(a,b).\r\nIt can be proven that solution always exist.","inputFormat":"The first line contains 2 integer a and b","outputFormat":"output integral value of x and y in a single line.","constraints":"1 &lt;= a, b &lt;= 10^6","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.util.Scanner;\r\n\r\npublic class Main {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\r\n\t}\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"","sampleOutput":"","questionVideo":"https://www.youtube.com/embed/H4AuhS7pN48","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"086949fa-3c5e-40c6-8a9c-f9be4b400318","name":"Number Theory For Experts","slug":"number-theory-for-experts","type":0},{"id":"5d1351ed-560a-4694-92f6-1e52560161ac","name":"Extended Euclidean Algorithm","slug":"extended-euclidean-algorithm","type":1}],"next":{"id":"494d08e9-b9e3-459b-9395-9a9de36aa28c","name":"Linear Diophantine Equation","type":1,"slug":"linear-diophantine-equation"},"prev":null}}` Editor

# Extended Euclidean Algorithm

medium

You have been given two Integers a and b. you need to find an integral solution of x and y such that a*x + b*y= gcd(a,b). It can be proven that solution always exist.

## Constraints

1 <= a, b <= 10^6

## Format

### Input

The first line contains 2 integer a and b

### Output

output integral value of x and y in a single line.

## Example

### Sample Output

Question Video

Discussions

Show Discussion

Related Resources 