test/8A.py
2026-07-01 19:46:51 +03:00

32 lines
No EOL
505 B
Python

import sys
data = sys.stdin.read().split()
a = int(data[0])
b = int(data[1])
c = int(data[2])
x0, x1 = 1, 0
y0, y1 = 0, 1
temp_a, temp_b = a, b
while temp_b != 0:
q = temp_a // temp_b
temp_a, temp_b = temp_b, temp_a % temp_b
x0, x1 = x1, x0 - q * x1
y0, y1 = y1, y0 - q * y1
g = temp_a
x = x0
y = y0
if c % g != 0:
print("Impossible")
else:
x *= c // g
y *= c // g
step = b // g
x = x % step
if x < 0:
x += step
y = (c - a * x) // b
print(x, y)