CT892

The Diophantine Apprentice: Solve ax + by = c

MediumAcceptance: 0.0%

In the ancient school of Prime City, the Mathematics Master presents a classic challenge: the linear Diophantine equation. Given integers a, b, and c, find integers x and y such that a*x + b*y = c. Such a solution exists if and only if gcd(a, b) divides c. "The Extended Euclidean Algorithm reveals all," the Master says, chalk in hand. "First find gcd(a, b) and the coefficients that express it. Then, if gcd divides c, scale the coefficients to get a particular solution." Given integers a, b, and c, find any integer solution (x, y) to a*x + b*y = c. If no solution exists, output "None". Output x and y separated by a space. The Master's constraints: -10^9 <= a, b, c <= 10^9, and a and b are not both zero From the Master's verified examples: Input: 2 3 7 Output: 2 1 Input: 4 6 3 Output: None The school's bell rings in the distance. Solve the equation, and you shall graduate from apprentice to journeyman mathematician.

Constraints:

-10^9 <= a, b, c <= 10^9, a and b not both zero

Tags:

diophantine extended-euclidean gcd number-theory math
Loading...
Test Cases:No test cases
No test cases available.
The Diophantine Apprentice: Solve ax + by = c - MEDIUM Coding Problem | CodeTikki